Sort.java
Select all
/* Sort.java David G. Klick CIS 260 2010-01-21 Class that performs a quicksort on an array of objects. */ public class Sort { public static
> void sort(T[] arr) { qsort(arr, 0, arr.length-1); } private static
> void qsort( T[] arr, int left, int right) { int lPtr = left; int rPtr = right; T pivot = arr[left]; while (lPtr < rPtr) { while ((arr[rPtr].compareTo(pivot) >= 0) && (lPtr < rPtr)) rPtr--; if (lPtr != rPtr) arr[lPtr++] = arr[rPtr]; while ((arr[lPtr].compareTo(pivot) <= 0) && (lPtr < rPtr)) lPtr++; if (lPtr != rPtr) arr[rPtr--] = arr[lPtr]; } arr[lPtr] = pivot; if (left < lPtr-1) qsort(arr, left, lPtr-1); if (right > lPtr+1) qsort(arr, lPtr+1, right); } }