Problem description:
Quick sortingAlgorithm
//******************************
// Description: quick sorting algorithm.
// Class Name: quicksort
// Author: Hong Xiaojun
// Time: 2004-11-2
//******************************
Public class Quicksort
{
Public void Quicksort (Int [], Int Left, Int Right) // Left is the first element position of array A, and right is the last element position of array.
{
Int I, j, temperature, temp; // Pivot
If (Left> = right)
Return ;
I = left;
J = right + 1;
Rows = A [left];
While ( True )
{
Do
{
I ++;
} While (A [I] <strong & I <right ); // Search for element greater than pivot from left to right
Do
{
J --;
} While (A [J]> Limit & J> 0 ); // Search for elements less than FULCRUM from right to left
If (I> = J)
Break ;
Else // If I <j is satisfied, the I and j position element values are exchanged.
{
Temp = A [I];
A [I] = A [J];
A [J] = temp;
}
}
A [left] = A [J];
A [J] = bytes; // Taking a [J] as the new pivot, the element values on the left of the J position are all less than a [J], and the element values on the right of the J position are all greater than a [J]
Quicksort (A, left, J-1 ); // Recursive sorting
Quicksort (A, J + 1, right );
}
}
the preceding Program is available in Microsoft Visual Studio. both NET 2003 and Visual C #2005 express edition beta1 have been debugged.