Skip to content

Instantly share code, notes, and snippets.

@mrpossoms
Created March 25, 2014 19:16
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 mrpossoms/9769098 to your computer and use it in GitHub Desktop.
Save mrpossoms/9769098 to your computer and use it in GitHub Desktop.
Javascript Linked List
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