Author: Li Huiqin,Hua Qing vision embedded college lecturer.
In essence, quick sorting is an improvement of "Bubble Sorting". The entire sorting process can be summarized as follows: the original sorting data is divided into several parts for segmented sorting through the n-hop sorting, in each sort process, the data to be sorted is divided into two parts by the specified Keyword: the larger part and the smaller part than the keyword, splits the entire to-be-arranged series into several small series and sorts them separately. Assume that we are sorting the number of columns quickly. The C language code is as follows:
# Include <stdio. h>
Int partition (int * data, int low, int high)
{Int T = 0;
T = data [low];
While (low
{While (low <High & Data [High]> = T)
High --;
Data [low] = data [High];
While (low <High & Data [low] <= T)
Low ++;
Data [High] = data [low];
}
Data [low] = T;
Return low;
}
Void sort (int * data, int low, int high) // re-determine the pivot during each trip in the fast sorting, determine the low and high values of each small record
{If (low> = high)
Return;
Int optional tloc = 0;
Required tloc = partition (data, low, high );
Sort (data, low, pivotloc-1 );
Sort (data, repeated tloc + 1, high );
}
Void quick_sort (int * data, int N) // calls the sort process.
{Sort (data, 0, n-1 );}
Int main ()
{Int I;
Int data [] = };
Quick_sort (data, sizeof (data)/sizeof (INT ));
For (I = 0; I <sizeof (data)/sizeof (INT); I ++)
Printf ("% d", data [I]);
Printf ("/N ");
Return 0;
}