public void sort() {
        // insertion sort routine
        if (head == null) {
            return;
        }

        Node<T> i = head;
        while (i.next != null) {
            // list[0..i] is sorted - loop invariant
            Node<T> j = i.next;
            Node<T> p = head;

            boolean jInserted = false;
            if (p.data.compareTo(j.data) > 0) {
                // insert j as head
                i.next = j.next;
                j.next = p;
                head = j;
                jInserted = true;
            } else {
                // insert j in list[0..i]
                while (p != i) {
                    if (p.next.data.compareTo(j.data) > 0) {
                        i.next = j.next;
                        j.next = p.next;
                        p.next = j;
                        jInserted = true;
                        break;
                    }
                    p = p.next;
                }
            }
            if (!jInserted) {
                i = i.next;
            }
        }
    }