-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink_list.py
More file actions
33 lines (27 loc) · 747 Bytes
/
Copy pathlink_list.py
File metadata and controls
33 lines (27 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import Union
class Node:
def __init__(self, data):
self.data = data
self.next: Node = None # type: ignore
class LinkedList:
def __init__(self):
self.head: Node = None # type: ignore
def append(self , data):
new_node: Node = Node(data)
if not self.head:
self.head = new_node
return
current = self.head
while current.next:
current = current.next
current.next = new_node
def display(self):
current: Node = self.head
while current:
print(current.data, end=" -> ")
current = current.next
linked_list = LinkedList()
linked_list.append(3)
linked_list.append(332)
linked_list.append(930)
linked_list.display()