Skip to content

Commit fe180ce

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1c36d44 commit fe180ce

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

data_structures/linked_list/middle_element_of_linked_list.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
from __future__ import annotations
22

3+
34
class Node:
45
"""Represents a node in the linked list."""
6+
57
def __init__(self, data: int) -> None:
68
self.data = data
79
self.next = None
810

11+
912
class LinkedList:
1013
"""Represents a linked list."""
14+
1115
def __init__(self) -> None:
1216
self.head = None
1317
self.size = 0 # Keep track of the list size
@@ -39,7 +43,8 @@ def __str__(self) -> str:
3943
while current:
4044
nodes.append(str(current.data))
4145
current = current.next
42-
return ' -> '.join(nodes)
46+
return " -> ".join(nodes)
47+
4348

4449
def find_middle_element(linked_list: LinkedList) -> int | None:
4550
"""
@@ -64,6 +69,7 @@ def find_middle_element(linked_list: LinkedList) -> int | None:
6469
slow_pointer = slow_pointer.next
6570
return slow_pointer.data
6671

72+
6773
if __name__ == "__main__":
6874
link = LinkedList()
6975
num_elements = int(input("Enter the number of elements: "))

0 commit comments

Comments
 (0)