// Routines to sort arrays of integers. // (c) 1997 duane a. bailey // modified to sort Vectors of Associations by allen tucker, 9/21/97 import structure.*; public class VectorInsertionSort { //+insertionSort public static void insertionSort(Vector data, int n) // pre: 0 <= n <= data.length // post: values in data[0..n-1] are in ascending order { int numSorted = 0; // number of values in place int index; // general index while (numSorted < n) { // take the first unsorted value and remove it Association temp = (Association)data.elementAt(numSorted); data.removeElementAt(numSorted); // ...and then find where it belongs among the sorted: index = numSorted; while (index > 0 && ((Association)data.elementAt(index-1)).lessThan(temp)) index--; // ...and then re-insert it data.insertElementAt(temp, index); numSorted++; } } //-insertionSort }