Created
July 24, 2013 15:06
-
-
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…
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
| 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