Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why is my code not working? What is the fix for this? Thanks. I DON'T NEED TO PROVIDE THE NODE CLASS. All you need to

Why is my code not working? What is the fix for this? Thanks.

I DON'T NEED TO PROVIDE THE NODE CLASS. All you need to do is try use the ADT methods that has been mentioned.

image text in transcribedimage text in transcribed

IMPORTANT: For this exercise, you will be defining a function which USES the Node ADT. A node implementation is provided. Your code can make use of any of the Node ADT methods: Node (), get_data(), set_data(), get_next(), set_next() add_after() and remove_after. The Node class is being used to implement a circular list, i.e. the next reference of the last node is not None, but points to the first node in the list. Define a function called print_circular_node_chain(first_node) which takes a Node object (a reference to a linked chain of nodes) as a parameter and prints its values (each node's value on a new line). You can assume that the chain is not empty. If the circular chain contains only one node, then the next pointer of that node will point to itself. IMPORTANT: the function needs to work for any non-empty circular chain of nodes and in particular also needs to work if adding or removing a node (as long as the chain is not empty). The following image illustrates the list used in the two examples below: first 'hello' 'world' For example: Test Result hello world first = Node('hello') y = Node('world') first.set_next(y) y.set_next(first) print_circular_node_chain(first) world hello first = Node('hello') y = Node('world') first.set_next(y) y.set_next(first) print_circular_node_chain(first.get_next() hello first = Node('hello') first.set_next(first) print_circular_node_chain(first) 1 2 3 4 def print_circular_node_chain(first_node): while first_node: print(first_node) first_node = first_node.get_next() Precheck Check Precheck only Test Expected Got x x hello world first - Node('hello') y = Node('world') first.set_next(y) y.set_next(first) print_circular_node_chain(first) hello world hello world hello world hello world hello

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

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions