快排

 1 viod quick_sort(int s[],int l,int r)
 2 {
 3     if(l<r)
 4     {
 5         int i = l,j = r,temp=s[l];
 6         while(i<j&&s[j]<temp)//右-左  第一个小于标记值
 7         {
 8             j--;
 9         }
10         if(i<j)
11         {
12             s[i++] = s[j];
13         }
14 
15         while(i<j&&s[i]>temp)//左-右 第一大于标记值
16         {
17             i++;
18         }
19         if(i<j)
20         {
21             s[j--] =s[i];
22         }
23     }
24     s[i]=temp;
25     quick_sort(s,l,i-1);
26     quick_sort(s,i+1,r);
27 }
View Code

 

posted @ 2020-04-23 16:31  GoingNow  阅读(109)  评论(0)    收藏  举报