递归排序之快速排序(挖坑法)
1 #include <stdio.h> 2 3 4 unsigned char standard(unsigned char* array,unsigned char low, unsigned char high) 5 { 6 unsigned char key = array[low]; 7 while(low<high) 8 { 9 while(low<high && array[high] >= key) 10 high--; 11 if(low < high) 12 array[low] = array[high]; 13 while(low<high && array[low] <= key) 14 low++; 15 if(low < high) 16 array[high] = array[low]; 17 } 18 array[low] = key; 19 return low; 20 } 21 22 void quicksort(unsigned char* array,unsigned char low, unsigned char high) 23 { 24 unsigned char no; 25 if(low < high) 26 { 27 no = standard(array,low,high); 28 if(no) 29 quicksort(array,low,no - 1); 30 quicksort(array,no + 1,high); 31 } 32 } 33 34 int main(void) { 35 unsigned char i; 36 unsigned char array[10] = {4,1,3,9,6,2,8,5,0,7}; 37 printf("Hello World\n"); 38 quicksort(array,0,9); 39 for(i=0;i<10;i++) 40 { 41 printf("%d\n",array[i]); 42 } 43 return 0; 44 }