Homework 7 - Extra Credit

Due: Wednesday March 18, 2009 at 10:00am (Before the final)
Absolutely NO late assignments will be accepted.

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

              List
           /       \
          /         \
     Linked         Stack
     List

ListNode class

This is the basic node for the list. This node will be a template class. It holds the data and the pointer to the next node.
Private variables
Public functions

List class

The List class is the base class from which the other two classes are derived. It has no real usable features to the main program. Its purpose is to define common functions the other two classes will use. These common functions are put in the protected section so only the derived classes can access them. Since it uses the ListNode class for a member variable, it is a template class. It has the following features:
Protected variables
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 specific values.
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

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 7 Menu
==============================================
1.  Test the linked list class with integers
2.  Test the linked list class with characters
3.  Test the stack class with integers
4.  Test the stack class with doubles

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

Linked List Menu

Implement this as a template function, similar to Homework 6.
               Linked List Menu
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. Insert a value at the head of the list
2. Search forwards for a value
3. Insert a value after the result of the previous search
4. Delete the first instance of a value
5. Print the list contents

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

Stack Menu

Implement this as a template function, similar to Homework 6.
          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
---------------------------------