快速排序C++代码实现

来源:互联网 发布:淘宝 赚 佣金 编辑:程序博客网 时间:2024/06/06 00:45
//交换位于i和j处的值void exchange(int *a,int i,int j){    int temp = a[i];    a[i] = a[j];    a[j] = temp;}int part(int *a,int low,int high){    int temp = a[high];    int i = low;    for (int j = low;j<high;++j)    {        if (a[j]<temp)        {            exchange(a,i,j);            ++i;        }    }    exchange(a,i,high);    return i;}void quicksort(int *a,int low,int high){    if (low<high)    {        int mid = part(a,low,high);        quicksort(a,low,mid-1);        quicksort(a,mid+1,high);    }}

0 0
原创粉丝点击