Skip to content

Commit 22e073d

Browse files
committed
Testing add to tail and add to head
1 parent 0724ff8 commit 22e073d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

linkedList.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ LinkedList.prototype.addToHead = function(value) {
1616
this.head = newNode;
1717
};
1818

19-
let ll = new LinkedList();
19+
LinkedList.prototype.addToTail = function(value) {
20+
let newNode = new Node(value, null, this.tail);
21+
if(this.tail) this.tail.next = newNode;
22+
else this.head = newNode;
23+
this.tail = newNode;
24+
}
25+
26+
let myLL = new LinkedList();
2027

21-
ll.addToHead(100);
22-
ll.addToHead(200);
23-
ll.addToHead(300);
28+
myLL.addToTail(10);
29+
myLL.addToTail(20);
30+
myLL.addToTail(30);
31+
myLL.addToHead(100);
2432

25-
console.log(ll);
33+
console.log(myLL.tail.prev.prev.prev);

0 commit comments

Comments
 (0)