We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e52f99f commit a3ca7bbCopy full SHA for a3ca7bb
chapter05/03-Doubly-Linked-List.js
@@ -42,11 +42,16 @@ function DoublyLinkedList() {
42
43
if (position === 0){ //add on first position
44
45
- node.next = current;
46
- current.prev = node; //NEW {1}
47
- head = node;
+ if (!head){ //NEW
+ head = node;
+ tail = node;
48
+ } else {
49
+ node.next = current;
50
+ current.prev = node; //NEW {1}
51
52
+ }
53
- } else if (position === length-1) { //last item //NEW
54
+ } else if (position === length) { //last item //NEW
55
56
current = tail; // {2}
57
current.next = node;
0 commit comments