Created
April 24, 2017 20:20
-
-
Save jeanmw/d668d0b5426b1ae585ac2a0b0d9ba0a7 to your computer and use it in GitHub Desktop.
This file contains 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 reverseLinkedList(node) { | |
var reversedPart = { | |
data: null, | |
next: null | |
} | |
var current = node; | |
while(current) { | |
let nextNode = current.next; | |
current.next = reversedPart; | |
reversedPart = current; | |
current = nextNode; | |
} | |
console.log("result is ", reversedPart) | |
return reversedPart; | |
} | |
reverseLinkedList({data: 2, next: {data: 4, next: {data: 5, next: {data: 12, next:null}}}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment