Skip to content

Instantly share code, notes, and snippets.

@jeanmw
Created April 24, 2017 20:20
Show Gist options
  • Save jeanmw/d668d0b5426b1ae585ac2a0b0d9ba0a7 to your computer and use it in GitHub Desktop.
Save jeanmw/d668d0b5426b1ae585ac2a0b0d9ba0a7 to your computer and use it in GitHub Desktop.
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