Quicksort
PROBLEM
Given an array
A. of
N elements the result of sorting the array in place is to arrange elements of
A. so that
A.1<=A.2<=...<=A.N
ALGORITHM
Quicksort by C. A. R. Hoare is a sorting algorithm in place. It has a worstcase running time that is O(N**2); its expected running time is O(N*lgN).
PRACTICE
It is often the best practical choice for sorting because it is remarkably efficient on the average. The following table compares four sorting algorithms. The A. array includes the integers in the range 1 to Max=10,100,1000,40000.
Running time in seconds for N=10000 

Algorithm 
Max = 100 
Max = 1000 
Max = 40000 
Max = 99999 
QUICKSORT 
4.66 
4.53 
4.89 
4.59 
HEAPSORT 
10.26 
10.67 
11.58 
11.18 
SHELLSORT 
7.45 
8.89 
10.58 
10.13 
COUNTING_SORT 
1.88 
1.95 
7.93 
31.85 
IMPLEMENTATION
Unit: nonrecursive internal subroutine
Global variables: array A. of arbitrary elements
Parameter: a positive integer N  number of elements in A.
Result:
Reordering of input array such that
A.1<=A.2<=...<=A.N
For sorting in descending order, you need only change the red coloured statements
do I = I while A.I > X; end
do J = J by 1 while X > A.J; end

CONNECTIONS
Literature
Cormen T. H., Leiserson Ch. E., Rivest R. L. Introduction to Algorithms
The MIT Press, Cambridge, 1990
Sedgewick R. Algorithms
AddisonWesley, Reading, Massachusetts, 1984
Wirth N. Algorithms and data structure
New Jersey, Prentice Hall, Inc., Engelwood Cliffs, 1986
Acknowledgement
I changed the test from Max=10 ... 40000 to Max=100 ... 99999. Thanks for idea go to Walter Pachl.
Note
This test ran in the Windows 2000 Professional environment on the computer with 132MB RAM and processor x86Family 6 Mode 6 Stepping 5.