Skip to content

London | 26-SDC-July | Raihan Sharif | Sprint 2 | Linked List - #267

Open
RaihanSharif wants to merge 11 commits into
CodeYourFuture:mainfrom
RaihanSharif:linkedList
Open

RaihanSharif wants to merge 11 commits into
CodeYourFuture:mainfrom
RaihanSharif:linkedList

Conversation

@RaihanSharif

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

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 remove method.

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.

@RaihanSharif RaihanSharif added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 24, 2026
@RaihanSharif

Copy link
Copy Markdown
Author

TODO: use sentinels (dummy head/tail) to simplify implementation

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest exploring the use of __slots__ to reduce memory usage?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 24, 2026
@RaihanSharif RaihanSharif added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 24, 2026
@cjyuan

cjyuan commented Oct 24, 2026

Copy link
Copy Markdown

Looks good.

Why not practice adding type hints?

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 24, 2026
@RaihanSharif

Copy link
Copy Markdown
Author

Why not practice adding type hints?

Oops, yeah, I meant to do that. I've done it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants