Skip to content

Commit 16dd246

Browse files
llist
1 parent 91747bb commit 16dd246

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

linked_list/v2_practise.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##singular linked list
2+
3+
class Node:
4+
def __init__(self, data):
5+
self.data = data
6+
self.next = None
7+
8+
class LinkedList:
9+
def __init__(self):
10+
self.head = None
11+
12+
def append(self, data):
13+
new_node = Node(data)
14+
15+
if self.head is None:
16+
self.head = new_node
17+
else:
18+
last = self.head
19+
while last.next:
20+
last = last.next
21+
last.next = new_node
22+
23+
def print_ll(self):
24+
current = self.head
25+
26+
while current:
27+
print(current.data, end=' --> ')
28+
current = current.next
29+
print("None")
30+
31+
ll1 = LinkedList()
32+
33+
ll1.append(1)
34+
ll1.append(2)
35+
ll1.print_ll()

0 commit comments

Comments
 (0)