Closed masuhar closed 7 years ago
With the following code, the display only shows nodes 888, 456, and 789 (i.e., 123 and 999 are disappeared).
class Node { constructor(val, next) { this.val = val; this.next = next; if (next != null) { this.next.prev = this; } } insertAfter(pos, value) { if (pos == 0) { var n = new Node(value,this.next); this.next = n; } else { this.next.insertAfter(pos-1, value); } } } var lst = new Node(123, new Node(456, new Node(789, null))); lst.insertAfter(0, 999); lst.insertAfter(1, 888);
(edit) Commenting out the lines 7-9 gives the hidden nodes back. So the assignment this.next.prev = this; might be the cause of the problem.
this.next.prev = this;
With the following code, the display only shows nodes 888, 456, and 789 (i.e., 123 and 999 are disappeared).
(edit) Commenting out the lines 7-9 gives the hidden nodes back. So the assignment
this.next.prev = this;
might be the cause of the problem.