Quick Sorting Algorithm
/* Date: 2014.12.14
Fast sorting method: similar to Bubble sorting, the algorithm performs sorting based on comparison and exchange, which improves the efficiency.
Process: 1). First, set a boundary value to divide the array into the left and right parts. The left sequence is less than or equal to it, and the right sequence is greater than or equal to it;
2) perform (1) operations for the sequence on the left and right respectively;
3). Repeat (2), which is equivalent to recursion until the order is reached.
Time Complexity: Worst O (n ^ 2), average O (nlogn ).
Space complexity: O (log2 (n)-O (n ).
It is an unstable sorting algorithm.
*/
Void QuickSort (int * arr, int left, int right)
{
Int f, temp;
Int ltemp, rtemp;
Ltemp = left;
Rtemp = right;
F = arr [(left + right)/2];
While (ltemp <rtemp)
{
While (arr [ltemp] <f)
{
++ Ltemp;
}
While (f <arr [rtemp])
{
-- Rtemp;
}
If (ltemp <= rtemp)
{
Temp = arr [ltemp];
Arr [ltemp] = arr [rtemp];
Arr [rtemp] = temp;
++ Ltemp;
-- Rtemp;
}
}
If (ltemp = rtemp)
{
Ltemp ++;
}
If (left <rtemp)
{
QuickSort (arr, left, ltemp-1 );
}
If (ltemp <right)
{
QuickSort (arr, rtemp + 1, right );
}
}