Saint Louis University |
Computer Science 180
|
Dept. of Math & Computer Science |
Topic: Linked Lists (Singly vs. Doubly)
Related Reading: Ch. 4.4, 4.5
Due:
Friday, 3 March 2005, 1:10pm
In discussing the design of linked lists, there are two particular design issues to consider.
Whether the list is singly or doubly linked.
Whether or not the list makes use of sentinel node(s)
Please make sure you adhere to the policies on academic integrity.
Creativity Exercise C-4.8 of the text.
Describe a non-recursive method for finding the middle node of a
doubly linked list with header and trailer sentinels, and an odd
number of real nodes between them. Moreso, your code must not
use any counters at all, but rather should "link hop" from the
two ends to determine the middle node.
NOTE: Please give a piece of C++ code as your solution.
Your method should be defined in the spirit of,
NodePtr middle(NodePtr headerL, NodePtr trailerL) {
where the return value is a reference to the middle node.
Creativity Exercise C-4.10 of the text.
NOTE: Please give a piece of C++ code as your solution. Your
method should be defined in the spirit of,
NodePtr concatenate(NodePtr headerL, NodePtr headerM) {
where the node returned is the header of the resulting list L'.
In creating the new list, you are free to damage or destroy the
original lists if you wish.
Please remember to report the running time!
A further hint can be found through Hint Server on textbook's website.
Creativity Exercise C-4.11 of the text.
NOTE: Please give a piece of C++ code as your solution. Your
method should be defined in the spirit of,
NodePtr concatenate(NodePtr headerL, NodePtr trailerL,
NodePtr headerM, NodePtr trailerM) {
where the node returned is the header of the resulting list L'.
In creating the new list, you are free to damage or destroy the
original lists if you wish.
Please remember to report the running time!
Page 188 of the text gives an implementation for the insertFirst method when using a doubly-linked lists, with header and trailer sentinels. The code was significantly simpler because of the use of those sentinels.
For this problem, we ask that you give an implementation for the insertFirst method if we chose to use doubly-linked lists, but without any sentinels. That is, assume that the deque class has two NodePtr data members, first and last which point directly to the nodes containing the first and last elements, respectively. Presumably, those pointers would be NULL pointers in the case of an empty deque.