Skip to content

Commit 59abeb1

Browse files
committed
update: added travese methos to return array of elements in LL
1 parent 9e01c43 commit 59abeb1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/_DataStructures_/LinkedList/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ class LinkedList {
156156
this.tail = this.head;
157157
this.size = 0;
158158
}
159+
160+
traverseList() {
161+
const arr = [];
162+
let node = this.head;
163+
while (node !== null) {
164+
arr.push(node.data);
165+
node = node.next;
166+
}
167+
return arr;
168+
}
159169
}
160170

161171
module.exports = { LinkedList, Node };

0 commit comments

Comments
 (0)