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

## Preliminaries

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:

The `ConsCell`s 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 `ConsCell`s to implement `SimpleList`s, this makes it difficult to retreat the cursor.

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

Constructors

• Construct a single node with contents c.
• Construct a single node with contents c, previous node p, and next node n.

Extractors

• Get the next node.
• Get the previous node.
• Get the contents.

Modifiers

• Set the next node. This should also modify the previous link in the next node.
• Set the previous node. This should also modify the next link in the previous node.
• Set the contents.

Static helper methods

• Print the list that starts with a particular node.

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 `DoublyLinkedNode`s. For example, to build the list (A,B,C), we might write.

```DoublyLinkedNode A = new DoublyLinkedNode("A");
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 `DoublyLinkedNode`s, implement the `SequencedList` interface that follows. You should call your implementation `DoublyLinkedSequencedList`.

The interface will follow.

## History

Wednesday, 5 April 2000

• Created

Thursday, 6 April 2000