Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

image text in transcribed

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

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

Step: 3

blur-text-image

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

understand the key issues concerning international assignments

Answered: 1 week ago