Chinaunix首页 | 论坛 | 博客
  • 博客访问: 343077
  • 博文数量: 122
  • 博客积分: 5000
  • 博客等级: 大校
  • 技术积分: 1191
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-24 11:12
文章分类

全部博文(122)

文章存档

2010年(122)

我的朋友

分类: C/C++

2010-04-29 13:04:02

int Partition(int * a, int low, int high)
{
    int pivotkey=a[low];
    int t=a[low];
    while(low<high)
    {
        while(low<high && a[high]>=pivotkey)--high;
        a[low]=a[high];
        while(low<high && a[low]<=pivotkey)++low;
        a[high]=a[low];
    }
    a[low]=t;
    return low;
}
void QuickSort(int * a,int low,int high)
{
    int pivotloc;
    if(low<high)
    {
        pivotloc=Partition(a,low,high);
        QuickSort(a,low,pivotloc-1);
        QuickSort(a,pivotloc+1,high);    
    }
}    


阅读(846) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~