class Node: def __init__(self, data = None, next = None): self.data = data self.next = next class LinkedList: def __init__(self): self.head = None def listprint(self): printval = self.head while printval is not None: print(printval.dataval) printval = printval.nextval def push(self, n): if self.head is None: self.head = Node(n) else: node = self.head while node.next is not None: node = node.next node.next = Node(n) def detectLoop(self): s = set() temp = self.head while (temp): if (temp in s): return True s.add(temp) temp = temp.next return False