Method One: Keep pits and determine a value at a time. http://blog.csdn.net/morewindows/article/details/6684558
#include <stdio.h>voidQsortint*array,intLen) { intvalue, start, end; if(Len <=1) return; Value= array[0]; Start=0; End= Len-1; while(Start <end) { for(; start < end;--end) { if(Array[end] <value) {Array[start++]=Array[end]; Break; } } for(Start < end; + +)start) { if(Array[start] >value) {Array[end--]=Array[start]; Break; }}} Array[start]=value; Qsort (array, start); Qsort (Array+start+1, len-start-1 );}intMain () {inta[Ten]={9,8,7,3,4,5,6,1,2,0};qsort (A,Ten);inti; for(i =0; I <Ten; i++) {printf ("%d", A[i]);} }
Method Two: Find two value Exchange http://developer.51cto.com/art/201403/430986.htm at a time
#include <stdio.h>inta[101],n;//define global variables, which need to be used in child functionsvoidQuicksortintLeftintRight ) { inti,j,t,temp; if(left>Right )return; Temp=a[left];//the base number is stored in temp.I=Left ; J=Right ; while(i!=j) {//The order is important, start looking from the right. while(A[j]>=temp && i<j) J--; //and find the right. while(A[i]<=temp && i<j) I++; //swap the position of two numbers in the array if(i<j) {T=A[i]; A[i]=A[j]; A[J]=T; } } //Finally, the base number is returned to the positiona[left]=A[i]; A[i]=temp; Quicksort (Left,i-1);//proceed to the left, here is a recursive processQuicksort (i+1, right);//proceed to the right, here is a recursive process} intMain () {inti,j,t; //read in Datascanf"%d",&N); for(i=1; i<=n;i++) scanf ("%d",&A[i]); Quicksort (1, n);//Quick Sort Call//results after sorting the output for(i=1; i<=n;i++) printf ("%d", A[i]); GetChar (); GetChar (); return 0; }
Two implementation ideas of "C-+ +" fast sorting