Assigned: Wednesday, April 5, 2000
Due: Friday, April 14, 2000
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:
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
SimpleLists, this makes it difficult
to retreat the cursor.
DoublyLinkedNode class. This class
should support the following methods.
Static helper methods
As before, we use
null to represent ``no node''.
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.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.
DoublyLinkedNodes, implement the
SequencedList interface that follows. You should call your
The interface will follow.
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 email@example.com