Starting from:
$30

$24

CSC1001 Assignment 4 Solution

Question 1

    1. This code is saved in 4_1.py.

    2. 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.

    3. 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.

    4. Execute as followings:























Question 2

    1. This code is saved in 4_2.py.

    2. 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.

    3. 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.
    4. Execute as followings:


Question 3

    1. This code is saved in 4_3.py.

    2. 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.

    3. The input can be anything, but only a positive integer number input can be executed.
    4. Execute as followings:

More products