We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 520aedc commit a8d67f8Copy full SHA for a8d67f8
singly_linkedList/singly_linked_list.js
@@ -46,7 +46,24 @@ class singlyLinkedList {
46
this.tail = prev;
47
this.tail.next = null;
48
this.length--;
49
- return prev;
+ if (this.length === 0) {
50
+ this.head = null;
51
+ this.tail = null;
52
+ }
53
+ return current;
54
55
+ shift() {
56
+ if (!this.head) {
57
+ return undefined;
58
59
+ const deleted = this.head;
60
+ this.head = this.head.next;
61
+ this.length--;
62
63
64
65
66
+ return deleted;
67
}
68
69
@@ -66,4 +83,6 @@ list.push("you");
83
console.log('traverse list: ');
84
list.traverse();
85
console.log('Deleted Node: ', list.pop());
86
+console.log('print List: ', list);
87
+console.log('Shifted Node: ', list.shift());
88
console.log('print List: ', list);
0 commit comments