(Latest Revision: 03/14/2004)

Book Collection Program


RATIONALE:

Writing this program will help you get a deeper understanding of binary search tree implementation issues. Also it will give you practice designing a new data structure.


THE ASSIGNMENT:

Write a program that keeps track of a book collection, allowing fast access by three different keys: title, author, and subject. It must simultaneously maintain the list in alphabetical order by all THREE keys.


INPUT:

The program inputs a series of commands from standard input. The commands are described in detail below.

The program must not expect any other input.


OUTPUT:

After reading each command the program echoes the command to standard output. It then executes the command and prints an appropriate response to the command on standard output.

The program also writes separator strings to standard output to separate the outputs corresponding to each input command.

The program must not write output of any other kind.


COMMANDS:

Input to the program will consist of a series of commands in the following forms.

Note: arguments like <subject> stand for VARIABLES which are strings terminated by end-of-line. Strings will have arbitrary amounts of leading, embedded, and trailing white space. The internal representation of the strings however are required *not* to have leading or trailing whitespace, and to have only single blanks between "words." (Here, a "word" is a contiguous string of characters that are not white space -- so something like the L. in L. Frank Baum would be called a word.)

Command names given below, like Insert, are literals and will appear in the input file exactly as they appear below.
COMMAND FORM:
Insert <author>
<title>
<subject>
SPECIFIC EXAMPLE:
Insert L. Frank Baum
    The   Wizard of  Oz
Children's Fantasy
EXAMPLE OF THE CORRESPONDING OUTPUT:
Insert L. Frank Baum; The Wizard of Oz; Children's Fantasy

... insertion complete ...
============================================================================
This command adds another book to the collection. It allocates a node, copies the data into it, and links the node into a structure that is three BST's in one. The structure simultaneously maintains the nodes in order by author, subject, and title. The details of the desired structure will be explained in class.

Note that in the real world two books can have the same author, or the same title, or the same subject. Your program must do something reasonable when there is a "tie" between two keys. To avoid some of the potential technical details, however, we will assume that titles are unique.
COMMAND FORM:
Delete  <title>
SPECIFIC EXAMPLE:
Delete  The    Wizard of Oz
EXAMPLE OF THE CORRESPONDING OUTPUT:
Delete The Wizard of Oz

... deletion complete ...
============================================================================
This command must cause a search for the named book. If the book is found, the pointers must be updated so that the book is now deleted from the multi-tree structure.

Note: You have to remove the node from three trees, one after the other. This constraint introduces a subtle difficulty: You can't use the "copy trick" described in our textbook to simplify the case of deleting a node that has two children. Do you see why?

We will discuss this issue in class.

If the book is not found, the procedure must leave the list and pointers unchanged, and simply print an appropriate message to the user.
COMMAND FORM:
List by <key>
SPECIFIC EXAMPLE:
List by title
EXAMPLE OF THE CORRESPONDING OUTPUT:
List by title

Andrew Tannenbaum
Structured Computer Organization
Computer Architecture

Douglas Comer
The Internet Book
Communications

L. Frank Baum
The Wizard of Oz
Children's Fantasy

Bruce Eckel
Thinking in C++
Programming Languages
============================================================================
This command must print out the contents of each indexCard in the list, in order according to the indicated key. The key can be either author, title, or subject. Use an attractive format.

If the list is empty, an appropriate message must be printed.
COMMAND FORM:
PrintTree by <key>
SPECIFIC EXAMPLE:
PrintTree by author
EXAMPLE OF THE CORRESPONDING OUTPUT:
PrintTree by author

            Andrew Tannenbaum
            Structured Computer Organization
            Computer Architecture

                        Bruce Eckel
                        Thinking in C++
                        Programming Languages

Douglas Comer
The Internet Book
Communications

            L. Frank Baum
            The Wizard of Oz
            Children's Fantasy
============================================================================
This command traverses the tree structure in reverse in-order and prints a "sideways" representation of the tree structure.
COMMAND FORM:
Quit
SPECIFIC EXAMPLE:
Quit
EXAMPLE OF THE CORRESPONDING OUTPUT:
Quit

Quit command received ... exiting.
============================================================================
This command must cause the program to Halt.
HELP:

Come to class to get help and hints.


WHAT TO TURN IN:

You will turn in three "phases" of this assignment:
  1. a level 2 version, and
  2. a level 3 version, and
  3. a final version.
For each phase of the assignment, you will turn in a printer output (hardcopy) and you will send me an e-mail message. Please follow these rules: Here is the list of things you have to turn in: Note that there are no spaces in the subject lines given. It is important that you do not insert any spaces. My e-mail address is: john@ishi.csustan.edu.


DUE DATES:

For due dates, see the class schedule.