-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathq1-2-ds.py
More file actions
46 lines (34 loc) · 751 Bytes
/
q1-2-ds.py
File metadata and controls
46 lines (34 loc) · 751 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
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def Circular(head):
if head==None:
return True
node = head.next
i = 0
while((node is not None) and (node is not head)):
i += 1
node = node.next
return(node == head)
# main
list1 = LinkedList()
list1.head = Node(1)
second = Node(2)
third = Node(3)
fourth = Node(4)
list1.head.next = second;
second.next = third;
third.next = fourth
if (Circular(list1.head)):
print('Yes')
else:
print('No')
fourth.next = list1.head
if (Circular(list1.head)):
print('Yes')
else:
print('No')