CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
|
|
@ -0,0 +1,27 @@
|
|||
function DoublyLinkedList(value, next, prev) {
|
||||
this._value = value;
|
||||
this._next = next;
|
||||
this._prev = prev;
|
||||
}
|
||||
// from LinkedList, inherit: value(), next(), traverse(), print()
|
||||
DoublyLinkedList.prototype = new LinkedList();
|
||||
|
||||
DoublyLinkedList.prototype.prev = function() {
|
||||
if (arguments.length == 1)
|
||||
this._prev = arguments[0];
|
||||
else
|
||||
return this._prev;
|
||||
}
|
||||
|
||||
function createDoublyLinkedListFromArray(ary) {
|
||||
var node, prev, head = new DoublyLinkedList(ary[0], null, null);
|
||||
prev = head;
|
||||
for (var i = 1; i < ary.length; i++) {
|
||||
node = new DoublyLinkedList(ary[i], null, prev);
|
||||
prev.next(node);
|
||||
prev = node;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
var head = createDoublyLinkedListFromArray([10,20,30,40]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue