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


Define a function that takes the head of a linked list as an argument and returns true if the linked list is circular, otherwise it returns false. A linked list is called circular if it is not NULL terminated and all nodes are connected in the form of a cycle. An empty linked list is considered as circular. All nodes have to be part of the cycle. The program prints 1 if the given linked list is circular, else 0. class Node(object): def _init_(self, value, next=None): self.next=next self. value=value def create_list(): n=int (input ()) k= int (input()) arr =input().split() x=int(arr[]) last =Node(x) x=int(arr[1]) head =Node(x, last ) for i in range (2,n) : x=int(arr[i]) head =Node(x, head ) if (k==1) : last. next = head return (head) def is_circular(head): \#write your code here node = create_list () if is_circular(node)==True: print(1) else: print(0)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
