Course Home | Homework | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science A220/P126
Data Structures and Object-Oriented Programming

Michael Goldwasser

Spring 2005

Dept. of Math & Computer Science

Homework Assignment 05

Linked Lists (Singly vs. Doubly)

Contents:


Overview

Topic: Linked Lists (Singly vs. Doubly)
Related Reading: Ch. 4.4, 4.5
Due: Friday, 4 March 2005, 1:10pm

In discussing the design of linked lists, there are two particular design issues to consider.

These two are truly independent issues. It so happens that Ch. 4.4 of the text introduces singly-linked lists which do not use sentinels, and then Ch. 4.5 of the text introduces soubly-linked lists which rely on the use of header and trailer sentinels. We could have consider the use of sentinels even with a singly linked list; we could equally have implemented doubly-linked lists even without sentinel nodes. In this homework we wish to explore these combinations.


Please make sure you adhere to the policies on academic integrity.


Practice Problems


Problems to be Submitted (20 points)

  1. (5 points)

    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.

  2. (5 points)

    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.

  3. (5 points)

    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!

  4. (5 points)

    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.


Michael Goldwasser
CS A220/P126, Spring 2005
Last modified: Monday, 07 March 2005
Course Home | Homework | Programming | Schedule & Lecture Notes | Submit