import java.util.*;

public class LinkedListTest {
    public static void main(String[] args) {
        LinkedList list = new LinkedList();
        System.out.println("The list is empty");
        list.showList();
        list.addToStart("Jam");
        list.addToStart("Bread");
        list.addToStart("Milk");
        System.out.println("After adding 3 items:");
        list.showList();
        int index = list.indexOf("Bread");
        System.out.println(
            "Found 'Bread' at index: " + index);
        System.out.println("At the index we retrieved: "
            + list.get(index));
        //list.removeFromStart();
        System.out.println(
            "After removing the first item:");
        list.showList();

        System.out.println("\n* Demo an iterator *");
        System.out.println("Using iterator to show:");
        Iterator it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        LinkedList.ListIter lit = list.iterator();
        System.out.println("Add at start");
        lit.add("Tea1");
        System.out.println("Add after moving next: ");
        lit.next();
        lit.add("Tea2");
        System.out.println("Add at end");
        while (lit.hasNext()) {
            lit.next();
        }
        lit.add("Tea3");
        list.showList();
        lit = list.iterator();
        System.out.println("Remove at start");
        lit.remove();
        System.out.println("Remove after moving next: ");
        lit.next();
        lit.remove();
        list.showList();
        System.out.println(
            "Remove at end should throw Exception");
        while (lit.hasNext()) {
            lit.next();
        }
        lit.remove(); // throws an exception
    }

}

