Homework 3
Due Date: Midnight, Monday, October 23
(NOTE: NO LATE HOMEWORKS WILL BE ACCEPTED.)
Assignment:
- Write a class definition for a doubly-linked list class called
List
. The class definition must contain the following
operations:
- List: default constructor (i.e., no arguments)
- ~List: destructor
- insertNode: insert a node anywhere in the list
- Input: position in the list that this node will be inserted as
- Input: data for the node to be inserted
- Output: none
- deleteNode: delete a node from any position in the list
- Input: position in the list of the node to be deleted
- Output: data of the node to be deleted
- getNumNodes: get the number of nodes in the list
- Input: none
- Output: number of nodes in the list
- isEmpty: check for an empty list
- Input: none
- Output: 1 = list is empty, 0 = list is not empty
- clearList: clear the list (i.e., remove all of the nodes)
A list node may be defined using either a struct
or a
class
. Make the data in the node generic (i.e., use either a
typedef
or a template class). Use whichever you feel
comfortable with as template classes have not yet been assigned as
reading.
- Embed the class definition in a complete C++ header file called
List.H
.
- Write stub (dummy) methods for each of the operations listed above.
For example, for a method called
anyMethod
that has no
parameters and returns an integer, the stub would look like:
int List::anyMethod()
{
return(1);
}
Place these methods in a file called
List.C
.
- Write a main function that simply instantiates an object of type
List
. Place the main function in a file called
main.C
.
- Create a makefile to compile and link your code into an executable
called
hw3
.
Homework Submission
Submit your makefile and all three source code files using the usual
submit
process.
Last Modified: