public void bubbleSort(boolean printpasses) {
        for (int pass = 1; pass < elements.length - 1; pass++) {
            int swapcount = 0;
            for (int i = 0; i < elements.length - pass; i++) {
                T current = elements[i];
                T other = elements[i + 1];
                int compResult = current.compareTo(other);
                if (compResult > 0) { //current is larger
                    elements[i] = other;
                    elements[i + 1] = current;
                    swapcount++;
                }
                if (compResult < 0) { //current is smaller
                    elements[i] = current;
                    elements[i + 1] = other;
                }
            }
            if (swapcount == 0) {
                return;
            }
            if (printpasses) {
                System.out.println(this);
            }
        }
    }