Skip to content

Commit a0e195d

Browse files
committed
Remove head
1 parent 22e073d commit a0e195d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

linkedList.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ LinkedList.prototype.addToTail = function(value) {
2323
this.tail = newNode;
2424
}
2525

26-
let myLL = new LinkedList();
26+
LinkedList.prototype.removeHead = function() {
27+
if(!this.head) return null;
28+
let val = this.head.value;
29+
this.head = this.head.next;
30+
if(this.head) this.head.prev = null;
31+
else this.tail = null;
32+
return val;
33+
}
34+
35+
let ll = new LinkedList();
2736

28-
myLL.addToTail(10);
29-
myLL.addToTail(20);
30-
myLL.addToTail(30);
31-
myLL.addToHead(100);
37+
ll.addToHead(1000);
38+
ll.addToHead(2000);
39+
ll.addToTail(3000);
3240

33-
console.log(myLL.tail.prev.prev.prev);
41+
ll.removeHead();
42+
console.log(ll.removeHead());

0 commit comments

Comments
 (0)