public static void sort(Comparable[] a) {
//what is missing here?
for(int j = i; j > 0 && less(a[j], a[j - 1]); j--) exch(a, j, j - 1);
}
private boolean less(int i, int j) {
return a[i].compareTo(a[j]) < 0;
}
private void exch(Comparable[] a, int i, int j) {
Comparable t = a[i];
a[i] = a[j];
a[j] = t;
}
public boolean sorted(Comparable[] a) {
for(int i = 1; i < a.length; i++) {
if(less(a[i], a[i - 1])) return false;
}
return true;
}
}
}