Hey Sapir,
Thanks for pointing out this method. You are right, I should have assigned node, instead of instantiating a new class in the if clause:
node
public insertInBegin(data: T): Node<T> { const node = new Node(data); if (!this.head) { this.head = node; } else { this.head.prev = node; node.next = this.head; this.head = node; } return node; }
It's a correct way because it also ensures that we return a reference to the node, which is assigned to the head. Thanks, I updated the code!
head
Got it! thank you.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hey Sapir,
Thanks for pointing out this method. You are right, I should have assigned
node
, instead of instantiating a new class in the if clause:It's a correct way because it also ensures that we return a reference to the node, which is assigned to the
head
. Thanks, I updated the code!Got it! thank you.