Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <T extends Comparable<? super T>> void merge(ArrayList<T> a, ArrayList<T> b){
- int curIndexOfA = 0;
- int curIndexOfB = 0;
- boolean bHasMoreBigElements = false;
- while(curIndexOfB < b.size()){
- if(a.get(curIndexOfA).compareTo(b.get(curIndexOfB)) >= 0){
- a.add(curIndexOfA, b.get(curIndexOfB));
- curIndexOfB++;
- }
- if(++curIndexOfA >= a.size()){
- bHasMoreBigElements = true;
- break;
- }
- }
- if(bHasMoreBigElements){
- for(;curIndexOfB < b.size(); curIndexOfB++){
- a.add(b.get(curIndexOfB));
- }
- }
- }
Add Comment
Please, Sign In to add comment