set tail as newNode if currentNode is the tail

This commit is contained in:
AbdelRahman Hamed 2023-04-08 02:21:33 +02:00
parent bbbfd32a45
commit 019c07e9e3

View File

@ -75,6 +75,9 @@ export default class LinkedList {
if (currentNode) {
newNode.next = currentNode.next;
currentNode.next = newNode;
if (this.tail === currentNode) {
this.tail = newNode;
}
} else {
if (this.tail) {
this.tail.next = newNode;