import java.util.Iterator; class SortertEnkelListe implements AbstraktSortertEnkelListe { public class Node { public Node next; public E val; Node(E val) { this.val = val; } } Node first; public void settInn(E val) { Node nw = new Node(val); if (first == null) { first = nw; return; } Node prev = null; Node curr = first; while (curr != null) { if (nw.val.compareTo(curr.val) <= 0) { nw.next = curr; if (prev == null) first = nw; else prev.next = nw; return; } prev = curr; curr = curr.next; } //Since we've not returned yet, this node is the biggest in the list prev.next = nw; } public E hent(String key) { Node n = first; while (n != null) { if (n.val.samme(key)) return n.val; n = n.next; } return null; } public Iterator iterator() { return new Iterator() { private Node n = first; public boolean hasNext() { return n != null; } public E next() { E val = n.val; n = n.next; return val; } }; } }