Skip to content

London | 26-JUL SDC | Ping Wang | Sprint 2 |Implement linked-list CYF-1180 - #230

Open
pathywang wants to merge 3 commits into
CodeYourFuture:mainfrom
pathywang:linked-list
Open

pathywang wants to merge 3 commits into
CodeYourFuture:mainfrom
pathywang:linked-list

Conversation

@pathywang

@pathywang pathywang commented Oct 4, 2026 •

Copy link
Copy Markdown

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 in Python with O(1) operations for adding elements at the head, removing elements from the tail, and removing specific elements using node handles.

@github-actions

This comment has been minimized.

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

@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.

a bit lost with assignment then with AL help,manage to understand and complete task

That's not a typical Changelist content and it does not convey what was changed in this PR. Could you rephrase it?

Comment on lines +1 to +5
class Node:
def __init__(self, value):
self.value = value
self.next = None
self.previous = None

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.

Thanks for the suggestion! I've added slots to the Node class to reduce per-instance memory overhead.

Comment on lines +31 to +36
if self.head == self.tail:
self.head = None
self.tail = None
else:
self.tail = node.previous
self.tail.next = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could consider delegating the node removing task to remove() -- less code to maintain.

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.

Thanks, yes I've updated pop_tail() to delegate node removal to remove(), avoiding duplicated logic.

Comment on lines +40 to +55
def remove(self, node):
if node == self.head and node == self.tail:
self.head = None
self.tail = None

elif node == self.head:
self.head = node.next
self.head.previous = None

elif node == self.tail:
self.tail = node.previous
self.tail.next = None

else:
node.previous.next = node.next
node.next.previous = node.previous No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: Look up why, in a doubly linked List implementation, assigning .next and .previous of the removed node to None a good practice?

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.

Thanks for the suggestion! I've updated remove() to set the removed node's next and previous references to None, ensuring it is fully detached from the list. I think the reason is that setting both pointers to None makes the removal explicit and prevents the removed node from retaining unnecessary references to neighboring nodes.

@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 9, 2026
@pathywang pathywang 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 9, 2026
@cjyuan

cjyuan commented Oct 10, 2026

Copy link
Copy Markdown

Changes look good. Well done.

@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 10, 2026
@pathywang

Copy link
Copy Markdown
Author

Many thanks, cjyuan.

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