Repository navigation
London | 26-SDC-July | Raihan Sharif | Sprint 2 | Linked List - #267
Open
RaihanSharif wants to merge 11 commits into
Open
RaihanSharif wants to merge 11 commits into
RaihanSharif wants to merge 11 commits into
Conversation
need doubly linked list to get O(1) insert at head, delete at tail and to delete a given node. push_head works.
…removing invalid nodes
Author
|
TODO: use sentinels (dummy head/tail) to simplify implementation |
cjyuan
reviewed
Oct 24, 2026
cjyuan
left a comment
There was a problem hiding this comment.
Code looks good.
Could consider adding type hints to each method to clearly specify the types of its parameters and return value.
Comment on lines
+1
to
+9
| class Node: | ||
| def __init__(self, value, owner): | ||
| self.value = value | ||
| self.prev = None | ||
| self.next = None | ||
| # this links a node to a specific list | ||
| # prevents attempt to remove a node from a list | ||
| # it does not belong to. | ||
| self.owner = owner |
There was a problem hiding this comment.
May I suggest exploring the use of __slots__ to reduce memory usage?
|
Looks good. Why not practice adding type hints? |
Author
Oops, yeah, I meant to do that. I've done it now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Task code
CYF-1180
Changelist
Implemented a doubly linked list which allows O(1) insertion at head, and removal at tail. Also allows O(1) removal of an arbitrary node, if a referece to it is passed in to the
removemethod.On top of this, to ensure the deletion is safe, each Node has an "owner" property, which is the list itself. So if a node from list x is passed into
y.remove(node)it won't try to remove it. Same with a node removed from the same list.Removed list has its next and previous points cleared so that those references don't keep the referred to nodes alive even after the list is gone.