Another kind of C ++ quick sorting
// Fast sorting II. cpp: Defines the entry point for the console application.
//
# Include "stdafx. h"
# Include <iostream>
# Define N 100
Using namespace std;
Double a [N];
Int qartition (double * a, int f, int t)
{
Double x = a [t];
Int I = F-1, j = f;
While (j <t)
{
If (a [j] <= x)
{
I ++;
Double temp = a [I];
A [I] = a [j];
A [j] = temp;
}
J ++;
}
Double temp = a [t];
A [t] = a [I + 1];
A [I + 1] = temp;
Return I + 1;
}
Void fast_sortII (double * a, int begin, int end)
{
If (begin <end)
{
Int q = qartition (a, begin, end );
Fast_sortII (a, begin, q-1 );
Fast_sortII (a, q + 1, end );
}
}
Int _ tmain (int argc, _ TCHAR * argv [])
{
Int cases;
Cout <"Enter the number of cases to be sorted:" <endl;
Cin> cases;
While (cases --)
{
Memset (a, 0.0, sizeof ());
Int n;
Cout <"Enter the number of elements to be sorted:" <endl;
Cin> n;
Cout <"Enter the elements to be sorted:" <endl;
Int I = 0;
For (I = 0; I <n; I ++)
{
Cin> a [I];
}
Cout <"Before sorting:" <endl;
For (I = 0; I <n; I ++)
{
Cout <a [I] <"";
}
Cout <endl;
Fast_sortII (a, 0, n-1 );
Cout <"after sorting:" <endl;
For (I = 0; I <n; I ++)
{
Cout <a [I] <"";
}
Cout <endl;
}
System ("pause ");
Return 0;
}
From the column heyongluoyao8