Update LinkedList.js

Traversing the list to find the last node and add the new data
This commit is contained in:
Marco 2019-08-26 23:38:43 +02:00 committed by GitHub
parent dc1047df72
commit 2dc6338165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,6 +48,12 @@ export default class LinkedList {
} }
// Attach new node to the end of linked list. // 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.next = newNode;
this.tail = newNode; this.tail = newNode;