Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions

Question

Distinguish between hearing and listening.

Answered: 1 week ago

Question

Use your voice effectively.

Answered: 1 week ago