Merging and sorting is completed. Now we can sort it quickly.
Simply put, quick sorting
Quick sorting is to set a set, an intermediate element, and then divide the set into three sets.
The subset of the left set is less than or equal to the intermediate element ---- the right subset is greater than or equal to the intermediate element
It can be solved by recursive calling,
Below is a simple and fast sorting, and there are many variant versions. Please refer to the relevant materials. Here is the original code.
//////////////////////////////////////// ///////////////// //////////////////////////////////////// //////////////////
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace fastsort
{
Class Program
{
Static void main (string [] ARGs)
{
Int [] arraytest = new int [] {, 5 };
Quicksort (arraytest,); // recursive call
Foreach (INT test in arraytest)
{
Console. Write (test. tostring () + "");
}
Console. Read ();
}
Static int partition (INT [] test, int P, int R) // separate the Core Algorithm for Bidirectional Scanning
{
Int I = P;
Int J = R + 1;
Int x = test [p];
While (true)
{
While (test [-- J]> X)
{
}
While (test [++ I] <X)
{
}
If (I <j)
{
Swap (test, I, j );
}
Else
{
Swap (test, P, J );
Return J;
}
}
}
Static void quicksort (INT [] test, int L, int R)
{
If (L> = r) // If the left and right are equal
{
Return;
}
Int M = partition (test, L, R );
Quicksort (test, L, M );
Quicksort (test, m + 1, R );
}
Static void swap (INT [] test, int X, int y)
{
If (x = y)
{
Return;
}
Int temp = test [x];
Test [x] = test [y];
Test [y] = temp;
}
}
}
S