The main goal of this lab is to get some practice writing code involving a singly linked list. We have written a driver which creates a singly-linked list of a given size, where the individual element values are chosen at random. The implementation for the list is as described in Ch. 4.3 of the text. In particular the head is a reference to the node of the list containing the first element. The node of the list which contains the final element will have a Next reference equal to null. (This is a different convention from the text's treatment of doubly-linked lists in Ch. 4.4.)
Your job is to write code for the following two routines in the file Student.java. We strongly recommend that you achieve success on the first task before you attempt the second.
The driver for this program is a Java Applet, which we have written to give you a graphical interface. The first thing you should do is to download all of the files we provide and compile and run them as given. If you are not yet familiar with how to run an Applet in your particular Java development platform, further details are given in the general programming webpage.
When you run the applet, you should see a singly-linked list of length 5 drawn on the screen. The challenge now is for you to implement the code for the size() and search() methods.
Although you will only need to modify one file (Student.java), you will need to
download several files we provide.
Be sure to test your program on a variety of situations. For
instance, you should test your size() routine to make sure that
it works properly on an empty list, or a list with only one or two
items. You should test your search() routine on special cases
such as searching for the very first item, the very last item, or for
an item which is not on the list.
When you have tested your methods and you are satisfied that they
work, please print out the modified file
Student.java and give this copy to the TA. Please make
sure that your name appears at the top of the page. You do not have
to submit anything electronically for this lab.
Testing
Handing in your completed lab
Last modified: 4 September 2002