import java.util.Arrays; class People { public static void main(String[] args) { Person[] peeps = new Person[5]; peeps[3] = new Person("Carl", "Rustad"); peeps[2] = new Person("Bill", "Jannen"); peeps[0] = new Person("Daniel", "Barowy"); peeps[4] = new Person("Jeannie", "Albrecht"); peeps[1] = new Person("Iris", "Howley"); System.out.println(Arrays.toString(peeps)); insertionSort(peeps); System.out.println(Arrays.toString(peeps)); } public static void insertionSort(Person[] ps) { int numSorted = 1; int i; while (numSorted < ps.length) { // take the first unsorted value Person tmp = ps[numSorted]; // ... and insert it among the sorted for (i = numSorted; i > 0; i--) { System.out.println("DEBUG: comparing: " + tmp + " with " + ps[i-1]); if (tmp.compareTo(ps[i-1]) < 0) { System.out.println("DEBUG: " + tmp + " is smaller."); ps[i] = ps[i-1]; } else { System.out.println("DEBUG: " + ps[i-1] + " is smaller; stopping."); break; } } // reinsert value System.out.println("DEBUG: " + tmp + " should be inserted in position " + i); ps[i] = tmp; numSorted++; } } }