# CS 340 - Machine Problem 4

## Inheritance of Linear Data Structures

Due: Thursday 11/9/2006 at 11:59 pm

For this assignment, you must implement four linear data structure using linked lists in either C++ or Java. All four of these data structures are to be connected in some inheritance hierarchy. Therefore you are not allowed to create 4 complete separate data structures for this assignment. Any assignment doing this will receive a zero for the assignment.

The following shows the classes and methods that are to exist. You will most likely also need a Node class.

1. a unordered list
• create an empty list (i.e. default constructor)
• listValue
• insert
• remove
• size
• print
2. a sorted list in increasing order
• create an empty list (i.e. default constructor)
• listValue
• insert
• remove
• size
• print
3. a queue
• create an empty list (i.e. default constructor)
• listValue
• insert
• remove
• size
• print
4. a stack
• create an empty list (i.e. default constructor)
• listValue
• insert
• remove
• size
• print

The following is to clarify any of the operations.

• For the insert operation on the unordered list, insert the value at the head of the list. For the ordered list, the smallest value should be at the beginning of the list. For a queue, insert at the end. For a stack, insert at the beginning of the list.
• For the listValue operation for the unordered list and sorted list, the method being executed is to prompt the user for a position and then display the the value at that position in the list of the item. The head of the list is position 1. For the queue and stack, display the value at the beginning of the list.
• For the remove operation for the unordered list and the sorted list, the method being executed is to prompt the user for the position of the node to be removed. A value of 1 should remove the value a the head of the list. For the queue and the stack, remove the value at the beginning of the list.
• The print operation is list all of the items in the list with the beginning of the list shown first.
• For the size operation, return the number of nodes in the list. Even though such an operation is normally not included with a queue or a stack, we will allow this operation for the
• The lists may have duplicate values stored in them.

### User Interface

Your program is to maintain 4 different lists. The user gets to determine the type of each list (unordered, ordered, queue, stack). The user will then get to specify the operation to be performed on each list. The following are commands are to processed by your program.
• c <num> <type>

Create a new list specified by <type> for list <num>.

The values of <num> will be the integers of 1, 2, 3 or 4.
The values of <type> will be the characters of u, o, q or s.

When a new list is created, the previous list should be emptied of its nodes (i.e. write a method to deallocate the previous list). If you wish, the 4 lists can be created when the program begins to whatever list type you desire. This way a user can call the insert command before the create command and not cause an error.

• i <num> <value>

Insert the integer <value> into list <num>.

The values of <num> will be the integers of 1, 2, 3 or 4.
The values of <value> could be any integer.

For the insert operation on the unordered list, insert the value at the head of the list. For the ordered list, the smallest value should be at the beginning of the list. For a queue, insert at the end. For a stack, insert at the beginning of the list.

• l <num>

List an value from list <num>.

The values of <num> will be the integers of 1, 2, 3 or 4.

For the listValue operation for the unordered list and sorted list, the method being executed is to prompt the user for a position and then display the the value at that position in the list of the item. The head of the list is position 1. For the queue and stack, display the value at the beginning of the list.

• r <num>

Remove an value from list <num>.

The values of <num> will be the integers of 1, 2, 3 or 4.

For the remove operation for the unordered list and the sorted list, the method being executed is to prompt the user for the position of the node to be removed. A value of 1 should remove the value a the head of the list. For the queue and the stack, remove the value at the beginning of the list.

• s <num>

Display the size of list <num>.

The values of <num> will be the integers of 1, 2, 3 or 4.

For the size operation, return the number of nodes in the list. Even though such an operation is normally not included with a queue or a stack, we will allow this operation for the project.

• p <num>

Print all the values from list <num>.

The values of <num> will be the integers of 1, 2, 3 or 4.

The print operation is list all of the items in the list with the beginning of the list shown first.

• h

Print some help about the commands used for this program.

• a

Print some information about the creator of this program. You should always identify your code.

• q

Quit this program.

Note that the angle brackets (less-than and greater-than signs) are not placed around the values. To create list one as a queue the command is:
```    c 1 q
not
c <1> <q>
```

``` turnin -c cs340 -p mp4 <filename(s)>
``` turnin -c cs340 -p mp4 -v