public class List { private Node first; public List() { first = null; } public boolean isEmpty() { if (first == null) return true; return false; } public int size() { Node current = first; int count = 0; while (current != null) { count++; current = current.next; } return count; } public T get(int n) { Node current = first; for (int i = 0; i < n; i++) { if (current == null) return null; current = current.next; } if (current == null) return null; return current.wert; } public void add(T val) { Node neu = new Node(); neu.wert = val; if (first == null) { first = neu; } else { Node current = first; while (current.next != null) { current = current.next; } current.next = neu; } } public void add(int n, T val) { if (n >=size()) { add(val); return; } Node neu = new Node(); neu.wert = val; if (n==0){ neu.next = first; first = neu; return; } Node current = first; for (int i = 0; i < n-1; i++){ current = current.next; } neu.next = current.next; current.next = neu; } public boolean contains(T val) { Node current = first; while (current != null) { if (current.wert.equals(val)) return true; } return false; } public T remove(int n) { if (n >= size()) return null; if (n == 0) { T tmp = first.wert; return tmp; } Node current = first; for (int i = 0; i< n-1; i++) { current = current.next; } T tmp = current.next.wert; current.next = current.next.next; return tmp; } public String toString(){ String result = ""; Node current = first; while (current != null) { result += current.wert + ", "; current = current.next; } return result; } }