CS120
Programming Assignment #9
Due Wednesday April 24th.
For this assignment you will be extending the node class. Using the
node class and associated code from class and make sure that it has
all of the following functionality. Some of this will already exist from
class, some will require modification of existing funcitons, and some
will require new functions.
- Begin by adding an additional data element to the node class. Currently
nodes only store a single int. Allow nodes to store at least one more piece of
data. For example, each node could store an int and a string (representing a
name and ID).
- A function print() to print a linked list starting at the head of
the list and printing to the end of the list (to the NULL, but not
printing the NULL). Make sure that
the new print() function prints both pieces of data (the int and the
new data element you added in part 1).
- A function reverse_print() to print a linked list backwards.
Remember that this is very similar to the print() function, but
prints the values "on the way out" of the list. Make sure the function
prints both peices of data.
- A function append() that adds data to the end of the list. This function
will have to take two arguments for the two pieces of data to be added.
- A function prepend() that adds data to the beginning of the list - right
after head. Note that this function is not part of the node class, it's a
stand alone function, because
it deals with the head pointer.
- A function insert() that adds data to the middle of the list based on the
int value of the data.
- A function delete_item() that deletes an element of the linked list based
on the new data type you added. For example, it might search for a particular
name and delete that node.
Extra Credit: There is a special case for the append() function
if the list is currently empty. The function append() is a function in the node class,
it looks for the NULL and adds a node to the end of the list. However,
if there are no nodes in the list the node has to be added right after the
head pointer. In this case the code has to act like the prepend() function.
To handle this special case you need a "wrapper" function that is not part of the node
class. The wrapper function checks to see if head points directly to NULL, in
which case it adds the new node and returns; otherwise it calls the node class's
append() function.
Turn in: A copy of the code and sample output showing all of the new
funciontality of the node class.