Created
March 19, 2014 09:03
-
-
Save ionox0/9638039 to your computer and use it in GitHub Desktop.
list merge for previously sorted JS linked lists. utilizes my Linked List class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function merge(list1, list2){ | |
var output = new LinkedList(); | |
while(list1 != null | list2 != null){ | |
console.log("asdf"); | |
if (!list2){ | |
output.add(list1.value); | |
list1 = list1.next; | |
} else if (!list1){ | |
output.add(list2.value); | |
list2 = list2.next; | |
} else if (list1.value < list2.value){ | |
output.add(list1.value); | |
list1 = list1.next; | |
} else if (list2.value < list1.value | !list1.value){ | |
output.add(list2.value); | |
list2 = list2.next; | |
} else { | |
output.add(list1.value); | |
list1 = list1.next; | |
list2 = list2.next; | |
} | |
} | |
console.log(output); | |
return output; | |
} | |
var list1 = {value:1, next:{value:2, next:{value:4, next:{value:8, next:null}}}}; | |
var list2 = {value:1, next:{value:3, next:{value:6, next:{value:8, next:{value:20, next:null}}}}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment