Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5e178ad
create a Node class that stores the value of the data it contains and…
HassanOHOsman Feb 26, 2026
d699eeb
Create anthor class that models the linked list
HassanOHOsman Feb 26, 2026
2886aeb
define a function that push a new node to the beginning of the linked…
HassanOHOsman Feb 26, 2026
1e691d7
check if the linked list have nodes, if so, appoints the new object t…
HassanOHOsman Feb 26, 2026
1ccff69
update the "former" head node's prev pointer to point to the new head…
HassanOHOsman Feb 26, 2026
361c2e3
make the new created node as the head node incase that the linked lis…
HassanOHOsman Feb 26, 2026
609ccd1
update logic so that it check if the linked list is empty if so to th…
HassanOHOsman Feb 26, 2026
f7ef01c
create pop_tail function that checks if the linked list has nodes in …
HassanOHOsman Feb 26, 2026
8daafeb
when linekd array has nodes, udpate pointers to get rid of the tail.
HassanOHOsman Feb 26, 2026
6abcd50
move the pointer to tail node to point the the previous node
HassanOHOsman Feb 26, 2026
4518f34
after repositioning pointer of last node towards the seond to last no…
HassanOHOsman Feb 26, 2026
8718bde
add if condition so that logic handles when linked list has more than…
HassanOHOsman Feb 26, 2026
6bce59e
update logic to handle when linked list is empty: Throw an error
HassanOHOsman Feb 26, 2026
97552b4
add a return to pop_tail to pass tests
HassanOHOsman Feb 26, 2026
1a94c7e
update pop_tail function to handle when there's one node in the linke…
HassanOHOsman Feb 26, 2026
5664fdd
since test require "previous", replacing all mentions to "prev" with …
HassanOHOsman Feb 26, 2026
b68f803
build remove function - make it check if there's a node before our cu…
HassanOHOsman Feb 26, 2026
3139f6d
update logic inside remove function so that when the current node is …
HassanOHOsman Feb 26, 2026
aec7441
updat remove function to handle when node points to other next node i…
HassanOHOsman Feb 26, 2026
a9ee5b0
ignore VM for Sprint 2
HassanOHOsman Feb 26, 2026
f54da60
create a branch so that pull request can be pushed
HassanOHOsman Feb 26, 2026
ad51df9
update read me to explain a new branch created for this task so a pul…
HassanOHOsman Feb 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sprint-2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv/
5 changes: 5 additions & 0 deletions Sprint-2/implement_linked_list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ It should support the following operations. Each operation should have a O(1) wo
* `remove` takes a handle from `push_head`, and removes that element from the list.

There are some tests in `linked_list_test.py` for your implementation - feel free to write more.

* A branch was later created so that a PR can be pushed.


* Make a new branch for implementing linked list in python
64 changes: 64 additions & 0 deletions Sprint-2/implement_linked_list/linked_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
class Node:
def __init__(self, data):
self.data = data
self.previous = None
self.next = None

class LinkedList:
def __init__(self):
self.head = None
self.tail = None

def push_head(self, data):
new_head_node = Node(data)
if self.head is not None:
new_head_node.next = self.head
self.head.previous = new_head_node

self.head = new_head_node
if self.tail is None:
self.tail = new_head_node

return new_head_node



def pop_tail(self):
if self.tail is not None:
tail_node = self.tail
previous = self.tail.previous
self.tail = previous
if self.tail is not None:
self.tail.next = None
else:
self.head = None
else:
raise IndexError("Unable to remove from empty linked list")

return tail_node.data



def remove(self, node):
if node.previous is not None:
node.previous.next = node.next
else:
self.head = node.next

if node.next is not None:
node.next.previous = node.previous
else:
self.tail = node.previous













Loading