Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Created July 24, 2013 15:06
Show Gist options
  • Select an option

  • Save PatrickJS/6071427 to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/6071427 to your computer and use it in GitHub Desktop.
Create a linked list that stores values without data structures Node in your linked list should be capable of storing any value (Number, String, Object, Function, etc), but you may not store a node's value as a property of any Object, Array, or even Function. The interface is completely up to you, however, the data structure you build must behav…
var Node = function (value, next){
var obj = {
get: function(){
return value;
}
};
if (next) {
next.next = obj;
}
return obj;
};
var root = new Node(7);
var node1 = root;
for(var i = 0; i < 10; i ++){
var node = new Node(i, node1);
node1 = node;
}
// var node2 = new Node(6, node1);
root.next.next.next.next.get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment