Skip to content

Commit e88a1f6

Browse files
committed
Add printReverse method
1 parent 6a95577 commit e88a1f6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: linked-list-double.js

+15
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ class DoublyLinkedList {
8686
console.log(list);
8787
}
8888
}
89+
90+
printReverse() {
91+
if (this.isEmpty()) {
92+
console.log("List is empty");
93+
} else {
94+
let curr = this.tail;
95+
let list = "";
96+
while (curr) {
97+
list += `${curr.value}<->`;
98+
curr = curr.prev;
99+
}
100+
console.log(list);
101+
}
102+
}
89103
}
90104

91105
const list = new DoublyLinkedList();
@@ -94,6 +108,7 @@ list.append(2);
94108
list.append(3);
95109
list.prepend(0);
96110
list.print();
111+
list.printReverse();
97112
list.removeFromEnd();
98113
list.print();
99114
list.removeFromFront();

0 commit comments

Comments
 (0)