Question: 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.

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

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

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!