public class List { public ListElem head; public List() { head = null; // Start with empty list } // ************************************************* // delete(): delete at head // ************************************************* public void delete() { ListElem p2; if ( head != null ) { head = head.next; // The second is the new "first element" } } // ------------------------------- // insert(v): insert at head // ------------------------------- public void insert(ListElem elem) { elem.next = head; // Link new element head = elem; } public void printList() { ListElem p; p = head; // Very important: start at first element System.out.print("List ==> "); while ( p != null ) { System.out.print(p + " "); // p.value accesses the value stored in list element p = p.next; // Make p points to the next element in list } System.out.print("\n\n"); } }