快速排序(看过最简单的一个版本)

int quciksort(int a[],int left,int right)
{
   if(left>=right || a==NULL) return;
   int i=left;
   int j=right;
   int tmp = a[left];//任选一个作为标尺
   while(i!=j)
     {
        while(a[j]>=tmp && i<j)  j--;
        while(a[i]<=tmp && i<j) i++;
        if(i<j)
        {
          swap(a[i],a[j]);
         }
     } 
    //标尺归位
    a[left] = a[i];
    a[i] = tmp;
    return i;
}

资料:http://developer.51cto.com/art/201403/430986.htm

http://baishi.baidu.com/watch/8840635721980127142.html?&recFrom=site&list=1&&page=videoMultiNeed

 

posted @ 2016-04-11 20:05  Daringoo  阅读(731)  评论(1编辑  收藏  举报