CS 368 Program 2: List Class Using Linked Lists

What to Write

Write a new version of the List class that uses a linked list to store the list items, rather than using an array, and write a new main function to test your List class. (Your list class should include all of the List methods described in the first assignment: the constructor, AddToEnd, Print, firstElement, nextElement, and hasMoreElements.)

You should implement linked lists by defining a class ListNode that contains two fields: an Object (the item stored in this node of the linked list) and a ListNode (the next item on the linked list). Remember that classes are implemented using pointers, so a ListNode really contains a pointer to an Object and a pointer to the next node on the list. Your List class should have ListNode fields instead of a field that is an array of Objects. You should define the ListNode class as a non-public class in the same file as your List class.

You should implement the List class so that the Print operation takes time proportional to the number of items on the list, and so that all of the other operations (including AddToEnd!) take constant time (i.e., are independent of the number of items already on the list).

What to Hand In

Put all of your code in a single file named List.java, and hand in your code through student files.

Grading Criteria

As for program #1, your grade will depend on: