Skip to content

Instantly share code, notes, and snippets.

@gurdasnijor
Created March 21, 2014 06:03
Show Gist options
  • Save gurdasnijor/9680450 to your computer and use it in GitHub Desktop.
Save gurdasnijor/9680450 to your computer and use it in GitHub Desktop.
function MergeLists(list1, list2) {
if (!list1) return list2;
if (!list2) return list1;
if (list1.data < list2.data) {
list1.next = MergeLists(list1.next, list2);
return list1;
} else {
list2.next = MergeLists(list2.next, list1);
return list2;
}
}
list1 = new LLNode(0,new LLNode(1, new LLNode(3,null)))
list2 = new LLNode(2,new LLNode(7, new LLNode(9,null)))
MergeLists(list1,list2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment