Combine two sorted linked list

View previous topic View next topic Go down

Combine two sorted linked list

Post  Admin on Thu Nov 10, 2011 5:42 pm

Recursive:
public class Merge{
public LinkedList output;
public void combine(LinkedListNode l1, LinkedListNode l2){
if(l1==null&&l2==null){
return;
}
else if(l1==null){
while(l2){
output.add(l2);
l2=l2.next;
}
}
else if(l2==null){}

else{
if(l1.value<l2.value){
output.add(l1);
combine(l1.next, l2);
}
else{
output.add(l2);
combine(l1,l2.next);
}
}
return;
}
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum