public class Lenkeliste { class Node { Node neste; T innhold; public Node(T x) { innhold = x; } public void settNeste(Node n) { neste = n; } public Node hentNeste() { return neste; } public T hentInnhold() { return innhold; } } int stoerrelse = 0; Node start; public void settInn(T x) { if (start == null) { start = new Node(x); stoerrelse++; } else { Node p = start; while (p.hentNeste() != null) { p = p.hentNeste(); } p.settNeste(new Node(x)); stoerrelse++; } } public void settInn(T x, int pos) { if (pos == 0) { Node ny = new Node(x); ny.settNeste(start); start = ny; } else { if (pos >= stoerrelse || pos < 0) { System.out.println("Ugyldig indeks"); } else { int i = 0; Node p = start; Node q = start; while (p.hentNeste() != null) { if (i == pos) { q.settNeste(new Node(x)); q.hentNeste().settNeste(p); return; } i++; q = p; p = p.hentNeste(); } q.settNeste(new Node(x)); q.hentNeste().settNeste(p); } } } public int stoerrelse() { return stoerrelse; } public void skrivUt() { Node p = start; while (p.hentNeste() != null) { System.out.println(p.hentInnhold()); p = p.hentNeste(); } System.out.println(p.hentInnhold()); } }