Created
March 25, 2014 19:16
-
-
Save mrpossoms/9769098 to your computer and use it in GitHub Desktop.
Javascript Linked List
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 ll(){ | |
this.last = this.first = null; | |
this.add = function(value){ | |
node = {value: value, next: null, prev: this.last}; | |
this.first = this.first ? this.first : node; | |
if(this.last) this.last.next = node; | |
this.last = node; | |
return node; | |
}; | |
this.remove = function(node){ | |
if(node.prev) node.prev.next = node.next; | |
if(node.next) node.next.prev = node.prev; | |
return node.value; | |
}; | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment