Answered step by step
Verified Expert Solution
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started