Question: Define a function that takes the head of a linked list as an argument and returns true if the linked list has a loop, otherwise

 Define a function that takes the head of a linked list

as an argument and returns true if the linked list has a

loop, otherwise it returns false. The definition of the linked list has

Define a function that takes the head of a linked list as an argument and returns true if the linked list has a loop, otherwise it returns false. The definition of the linked list has already been given to you. class Node: def_init_(self, data): self.data = data self.next = None class LinkedList: def _init__(self): self. head = None def push(self, new_data): new_node = Node (new_data) new_node . next = self. head self. head = new_node def printlist(self): temp = self.head while (temp): print (temp.data) temp = temp next def detectLoop(self): \#write your code here 11ist = LinkedList () n = int(input()) data = input () if n==len(datasplit()) : for i in data,split(): list.push(int(i)) def push(self, new_data): new_node = Node ( new_data ) new_node. next = self. . head self. head = new_node def printlist(self): temp = self.head while (temp): print (temp.data) temp = temp.next def detectLoop(self): \#write your code here llist = LinkedList () n=int( input ()) data= input() if n==len( data.split ( )): for i in data.split(): llist.push (int (i)) key = int(input ( )) if key ==1 : llist. head. next. next =11 ist. head; if ( llist.detectLoop( )): print ("True") else : print ("False")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!