This is a short assignment that illustrates the basics of inner classes. You will use both static inner classes and instance inner classes. To avoid naming conflicts, name the class LList.
Write a singly-linked list class. Your LList class should maintain a reference to both the front and rear node and be able to do the following:
For clone the general call will be something along the lines of:
public Object clone( ) { LList copy = null; copy = (LList) super.clone( ); // as a result of super.clone, front and back references // will be cloned. But that does not clone nodes. copy.makeEmpty( ); Iterator itr = this.iterator( ); while( itr.hasNext( ) ) copy.addRear( itr.next( ) ); return copy; }
There will be two private classes. First you will have a Node class which stores a single node in the list. Provide an appropriate set of constructors, and make everything in the node public. Second, you will have a LocalIterator class that is an instance inner class. LocalIterator should implement the Iterator interface. You do not have to provide a respectable implementation of remove, since that would be very difficult for a singly-linked list.
If you have never seen linked lists, here's a sample program that illustrates the ideas, without using inner classes.
To test your program, use a main that creates a LList does some insertions at both ends (use an Integer class), and then prints the list by enumerating through it. Here's a sample main.