Fundamentals of Computer Science II (CSC-152 2000S)


Assignment 4: Doubly-Linked Lists

Assigned: Wednesday, April 5, 2000
Due: Friday, April 14, 2000

Preliminaries

In this assignment, you will implement your own linked lists, using doubly-linked nodes rather than singly-linked nodes.

You should work in groups of size three. The members of your assignment group may not be members of your project group.

You may find the following files helpful:

Phase One: Doubly-Linked Nodes

The ConsCells that we've used to implement lists have one failing: they only provide a link to the next element and not the previous element. When we used ConsCells to implement SimpleLists, this makes it difficult to retreat the cursor.

Implement a DoublyLinkedNode class. This class should support the following methods.

Constructors

Extractors

Modifiers

Static helper methods

As before, we use null to represent ``no node''.

Phase Two: Quicksorting With Nodes

We can also build Scheme-like lists directly from the doubly-linked nodes. In this case, we don't really need a wrapper class; we just work direclty with DoublyLinkedNodes. For example, to build the list (A,B,C), we might write.

DoublyLinkedNode A = new DoublyLinkedNode("A");
DoublyLinkedNode B = new DoublyLinkedNode("B");
DoublyLinkedNode C = new DoublyLinkedNode("C");
A.setNext(B);
C.setPrev(B);

Note that we don't need to call B.setNext or B.setPrev because those calls are made implicitly in the other calls.

The traditional Quicksort algorithm is run on arrays. However, it is also possible to run a somewhat different Quicksort on linked lists. Here's the algorithm for an out-of-place Quicksort.

Quicksort(LinkedList ll) 
  if (ll contains less than two elements)
    return a new copy of ll;
  otherwise
    Object pivot = pick a pivot from ll;
    LinkedList smaller = the elements of ll smaller than pivot
    LinkedList equal = the elements of ll equal to pivot
    LinkedList larger = the elements of ll larger than pivot
    smaller = Quicksort(smaller);
    equal = Quicksort(equal);
    larger = Quicksort(larger);
    concatenate the three lists
    return the result

Implement Quicksort for doubly-linked lists. You may assume that all the elements of the list are strings.

Phase Three: A Wrapper Class

Using DoublyLinkedNodes, implement the SequencedList interface that follows. You should call your implementation DoublyLinkedSequencedList.

The interface will follow.

History

Wednesday, 5 April 2000

Thursday, 6 April 2000


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/2000S/Assignments/assign.04.html

Source text last modified Thu Apr 6 11:16:54 2000.

This page generated on Thu Apr 6 11:17:38 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at rebelsky@grinnell.edu