Skip to content

Commit 805e12c

Browse files
committed
Update doublyLinkedLists.js
1 parent 906b1dc commit 805e12c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Chapter6/doublyLinkedLists.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function LList() {
99
this.find = find;
1010
this.insert = insert;
1111
this.display = display;
12+
this.dispReverse = dispReverse;
13+
this.findLast = findLast;
14+
this.remove = remove;
1215
}
1316

1417
function find(item) {
@@ -41,3 +44,29 @@ function display() {
4144
}
4245
}
4346

47+
function dispReverse() {
48+
var currNode = this.head;
49+
currNode = this.findLast();
50+
while(currNode.previous != null) {
51+
console.log("Current:", currNode.element);
52+
currNode = currNode.previous;
53+
}
54+
}
55+
56+
function remove(item) {
57+
var currNode = this.find(item);
58+
currNode.previous.next = currNode.next;
59+
if (currNode.next != null) {
60+
currNode.next.previous = currNode.previous;
61+
}
62+
currNode.previous = null;
63+
currNode.next = null;
64+
}
65+
66+
function findLast() {
67+
var currNode = this.head;
68+
while(currNode.next != null) {
69+
currNode = currNode.next;
70+
}
71+
return currNode;
72+
}

0 commit comments

Comments
 (0)