/* date:2014.12.14
Quick sorting ideas: Similar to bubble sort, based on comparison and exchange to achieve sorting, improved efficiency.
Process: 1). First set a cutoff value, through which the array is divided into left and right parts, the left sequence is less than equal to it, and the sequence is greater than equal to it;
2). For the left and right sequences, perform (1) operations respectively;
3). Repetition (2), equivalent to recursion, until ordered.
Time complexity: Worst O (n^2), average O (Nlogn).
Spatial complexity: O (log2 (n))-O (n).
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);
}
}
Fast sorting algorithm