Created
September 11, 2012 15:03
-
-
Save egermano/3699476 to your computer and use it in GitHub Desktop.
Linked List
This file contains 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 LinkedList() { | |
this.head = null; | |
this.tail = null; | |
this.add = function(value) { | |
var node = new Node(value); | |
if (this.head == null) { this.head = node; } | |
if (this.tail != null) { this.tail.next = node; } | |
this.tail = node; | |
}; | |
} | |
function Node(value) { | |
this.value = value; | |
this.next = null; | |
} |
This file contains 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
var list = new LinkedList(); | |
list.add(1); | |
list.add(2); | |
list.add(3); | |
console.log(list); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment