class List { int value; List next; } public class delete { /* ==================================================== delete(h): delete the first elem from the list h return new list ==================================================== */ public static List delete (List h) { if ( h != null ) return (h.next); // Return new list that starts at h.next else return null; } public static void main(String[] args) { List head = null; // Insert for (int i = 1; i <= 10; i++) { List e = new List(); e.value = i; head = insert(head, e); // Insert i at head print(head); } // Delete for (int i = 1; i <= 10; i++) { head = delete(head); // Delete at head print(head); } } // Insert at head public static List insert (List h, List e) { e.next = h; return e; // Return new list that starts at e } // Print the list public static void print(List h) { while (h != null) { System.out.printf("%d ", h.value); h = h.next; } System.out.printf("\n"); } }