Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Combine two sorted linked list

Go down

Combine two sorted linked list Empty Combine two sorted linked list

Post  Admin 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

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

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