how this.tail.next = newNode is adding the value to next property of head? if it isn't then what part of the code is responsible to add next value to head?
constructor(value) {
this.head = {
value: value,
next: null
}
this.tail = this.head;
this.lenght = 1;
}
append(value) {
let newNode = {
value: value,
next: null
}
this.tail.next = newNode;
this.tail = newNode;
this.lenght++;
return this;
}
}
let myList = new LinkedList(10);
myList.append(8);
myList.append(8);
Output
head: { value: 10, next: { value: 8, next: [Object] } },
tail: { value: 8, next: null },
lenght: 3
}```