Skip to content

Commit 7a12426

Browse files
Merge pull request #2 from pinyoothotaboot/hotfix/fix-format
Fixed formated
2 parents da344c8 + f7df298 commit 7a12426

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

data_structures/linked_list/circular_doubly_linked_list.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class CircularDoublyLinkedList:
3131

3232
def __iter__(self) -> Iterator[Any]:
3333
"""
34-
Iterate through all nodes in the Circular Doubly Linked List yielding their data.
34+
Iterate through all nodes in the Circular Doubly Linked List yielding their
35+
data.
3536
Yields:
3637
The data of each node in the linked list.
3738
"""
@@ -41,6 +42,7 @@ def __iter__(self) -> Iterator[Any]:
4142
node = self.head
4243
while True:
4344
yield node.data
45+
assert node.next_node is not None
4446
node = node.next_node
4547
if node == self.head:
4648
break
@@ -67,13 +69,15 @@ def insert_tail(self, data: Any) -> None:
6769

6870
def insert_head(self, data: Any) -> None:
6971
"""
70-
Insert a node with the given data at the beginning of the Circular Doubly Linked List.
72+
Insert a node with the given data at the beginning of the Circular Doubly
73+
Linked List.
7174
"""
7275
self.insert_nth(0, data)
7376

7477
def insert_nth(self, index: int, data: Any) -> None:
7578
"""
76-
Insert the data of the node at the nth position in the Circular Doubly Linked List.
79+
Insert the data of the node at the nth position in the Circular Doubly
80+
Linked List.
7781
Args:
7882
index: The index at which the data should be inserted.
7983
data: The data to be inserted.
@@ -126,15 +130,17 @@ def insert_nth(self, index: int, data: Any) -> None:
126130

127131
def delete_front(self) -> Any:
128132
"""
129-
Delete and return the data of the node at the front of the Circular Doubly Linked List.
133+
Delete and return the data of the node at the front of the Circular Doubly
134+
Linked List.
130135
Raises:
131136
IndexError: If the list is empty.
132137
"""
133138
return self.delete_nth(0)
134139

135140
def delete_tail(self) -> Any:
136141
"""
137-
Delete and return the data of the node at the end of the Circular Doubly Linked List.
142+
Delete and return the data of the node at the end of the Circular Doubly
143+
Linked List.
138144
Returns:
139145
Any: The data of the deleted node.
140146
Raises:
@@ -144,7 +150,8 @@ def delete_tail(self) -> Any:
144150

145151
def delete_nth(self, index: int = 0) -> Any:
146152
"""
147-
Delete and return the data of the node at the nth position in Circular Doubly Linked List.
153+
Delete and return the data of the node at the nth position in Circular
154+
Doubly Linked List.
148155
Args:
149156
index (int): The index of the node to be deleted. Defaults to 0.
150157
Returns:
@@ -171,9 +178,10 @@ def delete_nth(self, index: int = 0) -> Any:
171178
self.tail.next_node = self.head
172179
else:
173180
# Find the node to delete
174-
delete_node: Node | None = self.head
181+
delete_node = self.head
175182
for _ in range(index):
176183
assert delete_node is not None
184+
assert delete_node.next_node is not None
177185
delete_node = delete_node.next_node
178186

179187
assert delete_node is not None
@@ -220,6 +228,7 @@ def traverse_backward(self) -> list[Any]:
220228
node = self.tail
221229
while True:
222230
result.append(node.data)
231+
assert node.prev_node is not None
223232
node = node.prev_node
224233
if node == self.tail:
225234
break

0 commit comments

Comments
 (0)