package sorting; import java.util.Vector; import java.util.Comparator; /** * Brad Miller's implementation of selection sort. * * @author Brad Miller. * @author Samuel A. Rebelsky */ public class BradSS implements Sorter { public void sort(Vector v, Comparator c) throws ClassCastException { Vector sorted = new Vector(); int sorts = v.size(); Object smallest = new Object(); for (int i = 0; i < sorts; ++i) { sorts = v.size();// on each runthrough vgets smaller, so we update sorts smallest = null; //start by clearing smallest for (int n = 0; n < sorts; ++n) { if (smallest.equals(null)) { smallest = v.get(n); }// if, youneed somethingto comare to else if (c.compare(v.get(n), smallest) < 0) { smallest = v.get(n); } } //for finds the smallest object in the given vector sorted.add(smallest); //adds smallest to the end of the sorted vector v.remove(smallest); //removes it from v, so as to not find it again in the future }//for, smallest object into the new vector v = sorted; //make the old vector the sorted one }// sort(Vector, Comparator) } // class BradSS