Homework 5 - Inheritance and Polymorphism

Due: Monday March 12, 2007 at 5pm

You will define four classes with the following hierarchy, plus a ListNode class for use by List.

              List
           /   |   \
          /    |    \
     Linked  Stack  Queue
     List

ListNode class

This is the basic node for the list. This assignment will use doubly linked nodes. This node will be for integers (ie not a template class).
Private variables
An integer for the data, a pointer for previous and a pointer for next.
Public functions

List class

The List class is the base type from which the other three classes are derived. It has no real usable features to the main program. Its purpose is to define common functions the other three classes will use. These common functions are put in the protected section so only the derived classes can access them. It has the following features:
Protected variables
A list node for head and a list node for tail
Protected functions
Public functions

LinkedList class

This class takes the base class and creates a fully working linked list. It will expand the base class to allow searching and deleting.
Public functions

Stack class

This will implement a stack that is derived from the base list class. It will define the push and pop functions.
Public functions

Queue class

This implements a queue that is derived from the base list class. It defines the add and remove functions.
Public functions

Menu Program

Once the classes are defined, code the following nested menu program to test that the classes work. A nested menu program has multiple menus that are selected from a main menu. When the program is first invoked, the main menu is presented. Options on the main menu give access to the sub-menus. For this assignment, use the following main menu:
   Welcome to the CS222 Homework 5 Menu
==========================================
1.  Test the linked list class
2.  Test the stack class
3.  Test the queue class

0.  Exit
==========================================
The submenus are defined as follows.

Linked List Menu

When Option 1 is selected, the linked list menu will be printed and the user can select any item off the linked list menu. When the user exits the linked list menu, they will return back to the Homework 5 menu. Do not exist the program until the user selects Option 0 in the Homework 5 menu.
               Linked List Menu
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. Insert a value at the head of the list
2. Insert a value at the tail of the list
3. Search forwards for a value
4. Search backwards for a value
5. Insert a value after the result of the previous search
6. Delete the first instance of a value
7. Delete the last instance of a value
8. Print the list contents

0. Return to main homework menu
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Options 3 and 4 should store the result of the previous search so it is available for Option 5. If there is no prior search result available, Option 5 should print an error and return to the menu.

Stack Menu

The stack menu is printed when Option 2 from the main homework menu is selected. As with the linked list menu, the stack menu should return to the main homework menu when the user selects Option 0.
          Stack Menu
---------------------------------
1. Push a value onto the stack
2. Pop a value off of the stack
3. Print the stack contents

0. Return to main homework menu
---------------------------------

Queue Menu

The queue menu is printed when Option 3 is selected from the main homework menu. As with the other two menus, selecting Option 0 in the queue menu should bring the user back to the main homework menu.
            Queue Menu
##################################
1. Add a value to the queue
2. Remove a value from the queue
3. Print the queue contents

0. Return to main homework menu
##################################