Programming project 6

Download the archive It contains all the files for this project.

Part 1: Doubly-Linked List

In this project, you should add several interesting methods to the doubly-linked list that we developed for our Josephus program in the lecture.

Your task is to implement the following methods of the DoublyLinkedList class. All of them must run in \(O(n)\) time:

Finally, implement the method takeout(n, m). It removes the part of the list from node n up to node m from the list, and returns it as a new DoublyLinkedList object. The operation must run in constant time (\(O(1)\) time), no matter how long the piece being removed is. Do not create any new nodes - you just use the nodes of the original list for the new list.

You can use the client script to perform a number of operations on DoublyLinkedList objects. It will also show you what the expected result is in each case.

Use the unit tests in for more stringent testing of your implementation.

Submission: Upload your file to the submission server.

Part 2: Circular List

In the Josephus program discussed in the class, we used a doubly-linked list to store the circle of participants.

Your task is to implement a circular linked list to simplify the implementation of the Josephus program.

In a circular list, the prev field of the first list node refers to the last list node, and the next field of the last list node refers to the first list node. (What does this mean when there is only one list node?)

There is no need for sentinels in a circular list. To simplify the design, we do not allow empty circular lists, so the constructor of the CircularList class takes an element argument and creates a circular list with one node.

Your task is to complete the implementation of the following methods:

Note that there is no prepend function, since for circular lists prepend and append are the same operation.

The script uses the CircularList class instead of the DoublyLinkedList class. Check that it returns the same results as from our lecture!

You can use the unit tests to test your implementations. Note that you must get string conversion working for the tests to work at all!

Submission: Upload your file to the submission server.