Lab 17 for May 29, 2003

Individual lab - Hand in on paper (you can print if the printer works, but do not count on that working)

Today you are to implement the following additions to the existing linked list object (here and here) oriented class that we have been developing for the last few weeks. 

First you need to implement a public method called remove that takes in a single integer argument that removes a single item from the linked list from a given index.  For a removal, remember you first need to find the node BEFORE the one you will delete, you need to save the pointer in the node you are deleting (so you don't lose the rest of the list), then set the pointer in the one to be deleted to 0 (so the deconstructor doesn't kill the rest of the list), delete the node, and then set the pointer of the node before the one to be deleted to the saved pointer value.  Next you need to implement an public overloaded assignment operator method.  This overloaded assignment method needs to first remove all existing nodes from your linked list (excepting the first one), copy the data from the first node of the rhs linked list, and then add new nodes in the current linked list that have the same data as in the rhs's linked list.  Lastly you need to implement a resize method that will take the existing linked list, and resize it to a given size.  If the new size is larger than the existing size, then add the correct number of new nodes to the end of the linked list.  If the new size is smaller than the existing linked list, you should remove the correct number of new nodes from the end of the linked list.

The prototypes as they will appear in llist3.h are as folllows:

void remove(int index);
llist& operator = (llist& rhs);
void resize(int newsize);


If this looks familiar, you might have done the homework.  If you have the homework with you, that means that you can jump straight into the extra credit portion of this lab alreay having credit for both the homework and the lab...  (I am evil, but I try to compensate you for being evil)  This extra credit is worth 10 points at most.

You are to implement the following methods for the class: a public method called sort that will sort all of the values of the node by value in ascending order.  You can use which ever sort you wish to for this as long as it works.  A public method called find that takes in an integer argument and returns a pointer to the node that has a data value the same as the integer argument (return 0 if none is found).  A public method called smaller than that takes in an integer argument and returns a pointer to the node that has the largest value smaller than the integer argument.  (you may find it helpful to copy the current linked list to a temporary one, and then sort it to find out the value of the node one smaller than the integer argument, then return the result of the find method)

The prototypes as they will appear in llist3.h are as follows:

void sort();
llist* find(int value);
llist* smaller(int value);

Note:  NO credit will be given for extra credit portions if the methods in the lab portion do not exist.  You have until tomorrow in class to complete the extra credit portion if you do not finish in lab, but the lab portion (the first 3 methods) are absolutely due at the end of lab.

ONLY HAND IN CODE FOR THE NEW METHODS