The basic idea of fast ordering is based on the divide-and-conquer strategy. For the input sequence AP. AR, if the scale is small enough to sort directly, otherwise three steps to deal with:
Decomposition (Divide): The sequence AP that will be entered. AR is divided into two non-null sequence AP. AQ and aq+1..ar to make AP. The value of any element in the AQ is less than the value of any element in the aq+1..ar.
Recursive Solution (Conquer): by recursion to P.. AQ and aq+1..ar are sorted.
Merge: Because the sort of the decomposed two subsequence is done in place, the AP ... AQ and aq+1..ar are sorted and do not need to perform any compute AP. AR has been sorted out.
This process of settlement is a basic step in accordance with the rule of partition. Therefore, the fast sorting method is one of the classical application examples of the partition method.
using System;
Namespace Vcquicksort
{
///<summary>
///classquicksort Quick Sort.
///Van Vicho
///</summary>
public class QuickSort
{
Public QuickSort ()
{
}
Private void Swap (ref int i,ref int J)
//swap two integer
{
int t;
t=i;
I=j;
j=t;
}
public void Sort (int [] list,int low,int High)
{
if (High<=low)
{
//only one element in array List
//so It do not need sort
return;
}
Else if (high==low+1)
{
//means two elements in array list
//so We just compare them
if (list[low]> List[high])
{
//exchange them
Swap (ref list[low],ref List[high);
return;
}
}
//more than 3 elements in the Arrary list
//begin QuickSort
Myquicksort (List,low,high);
}
public void myquicksort (int [] list,int low,int High)
{
if (Low {
int pivot=partition (li St,low,high);
Myquicksort (List,low, pivot-1);
Myquicksort (List,pivot+1,high);
}
}
Private int Partition (int [] list,int low,int High)
{
//get the pivot of the Arrary list
int pivot;
Pivot=list[low];
while (Low {
while (Low {
high--;
}
if (Low!=high)
{
Swap (ref list[low],ref List[high]);
low++;
}
while (Low {
low++;
}
if (Low!=high)
{
Swap (ref list[low],ref List[high]);
high--;
}
}
return to low;
}
}
}
Source: http://www.cnblogs.com/tanghuawei/archive/2006/10/19/533711.html