快速排序

 1 void quicksort(short int *array, int left, int right)
 2 {
 3     if(left < right)
 4     {
 5         int key = array[left];
 6         int low = left;
 7         int high = right;
 8         while(low < high)
 9         {
10             while((low < high)&&(array[high] >= key))
11             {
12                 high--;
13             }
14             array[low] = array[high];
15             while((low <high)&&(array[low] <= key))
16             {
17                 low++;
18             }
19             array[high] = array[low];
20         }
21         array[low] =key;
22         quicksort(array,left,low-1);
23         quicksort(array,low+1,right);
24     }
25 }

 

posted @ 2017-03-22 16:04  smilingfrog  阅读(161)  评论(0编辑  收藏  举报