London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 2 | Implement a linked list in python#146
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
The code in linked_list_test.py expects both .next and .previous properties of the removed node to be assigned None. Currently your implementation could not pass the tests.
Note: Do you know the why it is a good practice to assign .next and .previous of the removed node to None?
| if self.tail.previous: | ||
| self.tail = self.tail.previous | ||
| self.tail.next = None | ||
| else: | ||
| self.head = None | ||
| self.tail = None |
There was a problem hiding this comment.
Could consider delegating the node removing task to remove() -- less code to maintain.
|
Thanks @cjyuan, for your helpful feedback and suggestions. My tests were passing even without setting Do you know the why it is a good practice to assign .next and .previous of the removed node to None I think it's a good practice because if we still have access to the removed node, we could accidentally reach other nodes through its .next and .previous links. Setting them to None makes it clear that the node is no longer part of the list and helps avoid mistakes. Thanks again for taking the time to review it and point it out. |
|
Changes look good. I forgot to suggest looking into |
|
Closing PR because the SDC run has finished. Feel free to re-open if you're still working on it. |
Self checklist
Changelist
Implemented a doubly linked list supporting push_head, pop_tail, and remove operations in O(1) time.