Skip to content

doubly linked list: add dataclass and typing #12647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 1, 2025
Prev Previous commit
Next Next commit
Update doubly_linked_list_two.py
  • Loading branch information
MaximSmolskiy authored Apr 1, 2025
commit 43809bee2a2914d19f0bbfbb238e685bd8ca0df7
12 changes: 6 additions & 6 deletions data_structures/linked_list/doubly_linked_list_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __next__(self):
if not self.current:
raise StopIteration
else:
value = self.current.get_data()
value = self.current.data
self.current = self.current.get_next()
return value

Expand All @@ -48,14 +48,14 @@ def __str__(self):
current = self.head
nodes = []
while current is not None:
nodes.append(current.get_data())
nodes.append(current.data)
current = current.get_next()
return " ".join(str(node) for node in nodes)

def __contains__(self, value: int):
current = self.head
while current:
if current.get_data() == value:
if current.data == value:
return True
current = current.get_next()
return False
Expand All @@ -65,12 +65,12 @@ def __iter__(self):

def get_head_data(self):
if self.head:
return self.head.get_data()
return self.head.data
return None

def get_tail_data(self):
if self.tail:
return self.tail.get_data()
return self.tail.data
return None

def set_head(self, node: Node) -> None:
Expand Down Expand Up @@ -130,7 +130,7 @@ def insert_at_position(self, position: int, value: int) -> None:
def get_node(self, item: int) -> Node:
node = self.head
while node:
if node.get_data() == item:
if node.data == item:
return node
node = node.get_next()
raise Exception("Node not found")
Expand Down
Loading