From 2dc6338165f32aab37a21724e1be045843d038e5 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 26 Aug 2019 23:38:43 +0200 Subject: [PATCH] Update LinkedList.js Traversing the list to find the last node and add the new data --- src/data-structures/linked-list/LinkedList.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/data-structures/linked-list/LinkedList.js b/src/data-structures/linked-list/LinkedList.js index e256b1fe..5173a6e3 100644 --- a/src/data-structures/linked-list/LinkedList.js +++ b/src/data-structures/linked-list/LinkedList.js @@ -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;