Here's a good Quicksort template I wrote:

Code:

template <class number>
bool greater(number a, number b){
return (a > b);
}
template <class number>
bool less(number a, number b){
return (a < b);
}
//...these are the "internal" templates used by the algorithm...
template <class number>
int partition(number array[], int start, int finish, bool (*compare)(number, number) = greater) {
int pivot = start;
number value = array[pivot];
for( int index = start + 1; index < finish ; ++index )
if( !compare( array[index], value ) )
swap(array[index], array[++pivot]);
swap(array[start], array[pivot]);
return pivot;
}
template <class number>
void quicksort(number array[], int start, int finish, bool (*compare)(number, number) = greater) {
if(start < finish) {
int pivot = partition(array, start, finish, compare);
quicksort(array, start, pivot, compare);
quicksort(array, pivot + 1, finish, compare);
}
return;
}
//...and here is the user template...
template <class number>
void quicksort(number array[], int length, bool (*compare)(number, number) = greater) {
quicksort(array, 0, length, compare);
}