Skip to content

Instantly share code, notes, and snippets.

@zacharyhill
Created March 22, 2018 15:55
Show Gist options
  • Save zacharyhill/c2bd853928abbad2cf69aae8fe481879 to your computer and use it in GitHub Desktop.
Save zacharyhill/c2bd853928abbad2cf69aae8fe481879 to your computer and use it in GitHub Desktop.
LinkedList.prototype.reverse = function() {
var node = this.head;
var previous = null;
while (node !== null) {
var save = node.next;
node.next = previous;
previous = node;
node = save;
}
var save = this.head;
this.head = this.tail;
this.tail = this.head;
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment