all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
function LinkedList(value, next) {
|
||||
this._value = value;
|
||||
this._next = next;
|
||||
}
|
||||
LinkedList.prototype.value = function() {
|
||||
if (arguments.length == 1)
|
||||
this._value = arguments[0];
|
||||
else
|
||||
return this._value;
|
||||
}
|
||||
LinkedList.prototype.next = function() {
|
||||
if (arguments.length == 1)
|
||||
this._next = arguments[0];
|
||||
else
|
||||
return this._next;
|
||||
}
|
||||
|
||||
// convenience function to assist the creation of linked lists.
|
||||
function createLinkedListFromArray(ary) {
|
||||
var head = new LinkedList(ary[0], null);
|
||||
var prev = head;
|
||||
for (var i = 1; i < ary.length; i++) {
|
||||
var node = new LinkedList(ary[i], null);
|
||||
prev.next(node);
|
||||
prev = node;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
var head = createLinkedListFromArray([10,20,30,40]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue