Question: Define a function that takes the head of a circular linked list as an argument and prints all the elements of the list one by

 Define a function that takes the head of a circular linked

list as an argument and prints all the elements of the list

one by one separated by spaces. The defintion of the linked list

Define a function that takes the head of a circular linked list as an argument and prints all the elements of the list one by one separated by spaces. The defintion of the linked list has already been provided to you. Note: Input items are inserted at the front of the linked list that is why the output is in reverse order. klass Node: def init_(self, data): self.data = data self.next = None class CircularLinkedList: def__init_(self): self.head = None def push(self, data): ptr1 = Node ( data ) temp = self. head ptr1.next = self.head if self.head is not None: while(temp.next != self.head): temp = temp.next temp.next =ptr1 else: ptr1. next = ptr 1 self. head = ptr 1 def printlist(self): \#write your code here 6 - class CircularLinkedList: 7. def_init_(self): self. head = None def push(self, data): ptr1 = Node ( data ) temp = self.head ptr1. next = self. head if self.head is not None: while(temp.next != self.head): temp = temp.next temp.next =ptr1 else: ptr 1. next =ptr1 self.head = ptr 1 def printlist(self): \#write your code here cllist = CircularLinkedList () n=int( input ()) data= input () if n==len( data.split()): for i in data.split(): cllist.push(int(i)) cllist.printList()

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!