Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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