-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinglyLL.py
More file actions
52 lines (34 loc) · 885 Bytes
/
SinglyLL.py
File metadata and controls
52 lines (34 loc) · 885 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Node:
def __init__(self, val):
self.val = val
self.next = None
class SinglyLL:
def __init__(self):
self.head = None
def append(self, val):
new_node = Node(val)
if self.head is None:
self.head = new_node
return
curr = self.head
while curr.next is not None:
curr = curr.next
curr.next = new_node
def traverse(self):
if not self.head:
print("SLL is empty")
else:
curr = self.head
while curr is not None:
print(curr.val, end=" ")
curr = curr.next
print()
SLL = SinglyLL()
SLL.traverse()
# ll = SinglyLL()
# ll.append(5)
# ll.append(10)
# ll.append(15)
# print(ll.head.val)
# print(ll.head.next.val)
# print(ll.head.next.next.val)