public class LinkedList implements List { protected static class ListNode implements List.Node { public int data; public ListNode next; public int getData() { return data; } ListNode() { data = 0; } ListNode (int x) { data = x; } } int length = 0; ListNode head = new ListNode(); ListNode tail = new ListNode(); LinkedList() { head.next = tail; tail.next = null; } public void add(int a) { ListNode ln = new ListNode(a); ln.next = head.next; head.next = ln; length ++; } public Node find(int a) { ListNode aktuell = head; while (aktuell.next != null) { if (a == aktuell.data) return aktuell; else aktuell = aktuell.next; } return null; } public Node getFirst() { return head.next; } public Node getLast() { ListNode aktuell = head; while (aktuell != null) { if (aktuell.next == null) return aktuell; else aktuell = aktuell.next; } return null; } public Node getNext(Node e) { return getListNode(e).next; } public Node getPrevious(Node e) { ListNode aktuell = head; while (aktuell != null) { if (aktuell.next == e) return aktuell; else aktuell = aktuell.next; } return null; } public void insert(Node n, int a) { ListNode neu = new ListNode(a); ListNode ln = getListNode(n); neu.next = ln.next; ln.next = neu; length ++; } public void remove(int a) { Node n = find(a); remove(n); } public void remove(Node e) { ListNode weg = getListNode(e); Node n = getPrevious(e); ListNode davor = getListNode(n); davor.next = weg.next; length --; } public int size() { return length; } public ListNode getListNode (Node a) { ListNode aktuell = head; while (aktuell.next != null) { if (aktuell.equals(a) == true) return aktuell; else aktuell = aktuell.next; } return null; } }