Description
Question 1
-
This code is saved in 4_1.py.
-
The program contains 2 classes: Node, SinglyLinkedList. The SinglyLinkedList contains a method named recursive_count which recursively counts the number of nodes in a singly linked list.
-
The input of the recursive_count function should be a reference pointing to the first node of the linked list. The output of the function should be the number of nodes in that linked list.
-
Execute as followings:
Question 2
-
This code is saved in 4_2.py.
-
The program contains 2 classes: Node, SinglyLinkedList. The SinglyLinkedList contains a method named quick_sort which uses quick sort algorithm to sort over a singly linked list.
-
The input of your function should be a reference pointing to the first node of a linked list, and the output of your function should also be a reference to the first node of a linked list, in which the data have been sorted into the ascending order.
-
Execute as followings:
Question 3
-
This code is saved in 4_3.py.
-
The program prompts user to input the number of disks in Tower of Hanoi game. After that, it will print out the steps to move all the disks from rod A to rod C via rod B.
-
The input can be anything, but only a positive integer number input can be executed.
-
Execute as followings: