public class List { private ListElement head; public void insert(ListElement elem) { elem.next = head; head = elem; } public void insert(ListElement newElem, int i) { if (i == 0) insert(newElem); else { ListElement tmp = head; ListElement prev = null; int l = 0; // Aufsuchen des i-ten Elements while (l < i) { prev = tmp; tmp = prev.next; l++; } // l == i ist erreicht prev.next = newElem; newElem.next = tmp; } } public boolean delete() { if (head == null) { return false; } head = head.next; return true; } public boolean isEmpty() { return head == null; } public int length() { int count = 0; ListElement current = head; while (current != null) { count++; current = current.next; } return count; } public void show() { ListElement current = head; if (current == null) { System.out.println("List is empty."); return; } System.out.print("List: "); while (current != null) { System.out.print(current.data + " -> "); current = current.next; } System.out.println("null"); } }