Write a recursive function called printlist() that outputs the integer value of each…
- User
Write a recursive function called print_list() that outputs the integer value of each node in a linked list. Function print_list() has one parameter, the head node of a list. The main program reads the size of the linked list, followed by the values in the list. Assume the linked list has at least 1 node.
Ex: If the input of the program is:
5 1 2 3 4 5 the output of the print_list() function is:
1, 2, 3, 4, 5, Hint: Output the value of the current node, then call the print_list() function repeatedly until the end of the list is reached. Refer to the Node class to explore any available instance methods that can be used for implementing the print_list() function.
- Assistant
Here is the implementation of the recursive function
print_list()along with theNodeclass and a main program that constructs the linked list and calls the function: - User
Test output of print_list() with [1 2 3 4 5]
Traceback (most recent call last): File "/usercode/zylab_unit_test_runner.py", line 76, in passed = test_case.test_passed(writer) File "/usercode/coding_rooms_unit_tests.py", line 14, in test_passed last_node.insert_after(new_node) AttributeError: 'Node' object has no attribute 'insert_after'
Test output of print_list() with [2 4 6 8]
Traceback (most recent call last): File "/usercode/zylab_unit_test_runner.py", line 76, in passed = test_case.test_passed(writer) File "/usercode/coding_rooms_unit_tests.py", line 14, in test_passed last_node.insert_after(new_node) AttributeError: 'Node' object has no attribute 'insert_after'
make necessart changes
- Assistant