mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-10 11:09:43 +08:00
Update LinkedList.js
Traversing the list to find the last node and add the new data
This commit is contained in:
parent
dc1047df72
commit
2dc6338165
@ -48,6 +48,12 @@ export default class LinkedList {
|
||||
}
|
||||
|
||||
// Attach new node to the end of linked list.
|
||||
let current = this.head;
|
||||
while (current.next !== null) {
|
||||
current = current.next;
|
||||
}
|
||||
current.next = newNode;
|
||||
|
||||
this.tail.next = newNode;
|
||||
this.tail = newNode;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user