Skip to content

Instantly share code, notes, and snippets.

@aamirafridi
Created August 18, 2020 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aamirafridi/7bc7eb48c36bfc6c958f2ccb4683f78a to your computer and use it in GitHub Desktop.
Save aamirafridi/7bc7eb48c36bfc6c958f2ccb4683f78a to your computer and use it in GitHub Desktop.
Reversing a doubly linked list in Javascript
function reverse(head) {
let nextNode = null;
let prevNode = null;
let currentNode = head;
while(currentNode) {
nextNode = currentNode.next;
currentNode.prev = nextNode;
currentNode.next = prevNode;
prevNode = currentNode;
currentNode = nextNode;
}
return prevNode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment