Manchester | 25-SDC-Nov | Rahwa Haile | Sprint 2 | Implement a linked list in Python#121
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
69d651d to
602505d
Compare
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 all 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.head == self.tail: | ||
| self.head = None | ||
| self.tail = None | ||
| else: | ||
| self.tail = self.tail.previous | ||
| self.tail.next = None |
There was a problem hiding this comment.
Could consider delegating this task to remove() -- less code to maintain.
|
@cjyuan I appreciate the explanation about why it is a good practice to assign .next and .previous good practice—it makes sense for memory management, preventing accidental traversal, and making debugging easier. |
|
The code in The tests in def test_remove_middle(self):
l = LinkedList()
l.push_head("a")
b = l.push_head("b")
l.push_head("c")
l.remove(b)
self.assertIsNone(b.next)
self.assertIsNone(b.previous)
self.assertEqual(l.pop_tail(), "a")
self.assertEqual(l.pop_tail(), "c") |
Manchester | 25-SDC-Nov | Rahwa Haile | Sprint 2 | Implement a linked list in Python
Learners, PR Template
Self checklist
Implement a Doubly-Linked List in Python
Description
Implemented a complete doubly-linked list data structure with O(1) worst-case time complexity for all required operations.
Changes
Nodeclass with pointers to next and previous nodesLinkedListclass with efficient head/tail managementPlease review my work — thank you!