-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_linked_list.py
More file actions
42 lines (31 loc) · 935 Bytes
/
circular_linked_list.py
File metadata and controls
42 lines (31 loc) · 935 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
class Node:
def __init__(self,data):
self.data = data
self.next = None
class Circular_Linked_List:
def __init__(self):
self.head = None
def push(self, data):
new_node = Node(data)
temp = self.head
new_node.next = self.head
#if linked list is not none then set the next of last node
if self.head is not None:
while(temp.next != self.head):
temp = temp.next
temp.next = new_node
else:
new_node.next = new_node
self.head = new_node
def print_list(self):
temp = self.head
while temp.next != self.head:
print(temp.data)
temp = temp.next
print(temp.data)
cll = Circular_Linked_List()
cll.push("10")
cll.push("9")
cll.push("6")
cll.push("3")
cll.print_list()