Java tutorial
//package com.java2s; import java.util.Comparator; public class Main { public static <T> void quicksort(T[] array, Comparator<? super T> c) { quicksort(array, 0, array.length - 1, c); } public static <T> void quicksort(T[] array, int left0, int right0, Comparator<? super T> c) { int left, right; T pivot, temp; left = left0; right = right0 + 1; final int pivotIndex = (left0 + right0) / 2; pivot = array[pivotIndex]; temp = array[left0]; array[left0] = pivot; array[pivotIndex] = temp; do { do left++; while (left <= right0 && c.compare(array[left], pivot) < 0); do right--; while (c.compare(array[right], pivot) > 0); if (left < right) { temp = array[left]; array[left] = array[right]; array[right] = temp; } } while (left <= right); temp = array[left0]; array[left0] = array[right]; array[right] = temp; if (left0 < right) quicksort(array, left0, right, c); if (left < right0) quicksort(array, left, right0, c); } }