-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A little confused about the While condition in doubly-linked-list.js
insertBefore and insertAfter
#51
Comments
doubly-linked-list.js
insertBefore and insertAfter
doubly-linked-list.js
insertBefore and insertAfterdoubly-linked-list.js
insertBefore and insertAfter
In your function call const { DoublyLinkedList } = require( "./doubly-linked-list.js");
const doublyLinkedList = new DoublyLinkedList();
doublyLinkedList.add(1);
doublyLinkedList.add(2);
doublyLinkedList.add(3);
doublyLinkedList.insertAfter(10, 1);
for(let i of doublyLinkedList.values())
console.log(i)
// 1, 2, 10, 3 |
It is, the index 1 doesn't exist. I do it on purpose. My point is, if the index is exceed, the error should be throw by
and should not be throw by the the exception.
I think that is caused by the while condition |
|
Can you assign this to me |
class Node { class DoublyLinkedList { insertBefore(nodeToInsert, node) {
} insertAfter(nodeToInsert, node) {
} |
~/computer-science-in-javascript/src/data-structures/doubly-linked-list/doubly-linked-list.js
I am confused about the difference of while condition between line 183 and 259,
and do a test in node for the insertAfter method:
and it will throw an the error below, it's not a expected error throw by the doubly Linked List class.
So I think
current.next !== null
in insertBefore method is right for insertAfter, instead ofcurrent !== null
The text was updated successfully, but these errors were encountered: