首页 新闻 会员 周边 捐助

C++写的这个快速排序不对啊,能帮我看看哪里出问题了吗?

0
悬赏园豆:20 [已解决问题] 解决于 2014-08-19 10:22
#include <iostream>
using namespace std;

int Partition(int A[], int low, int high)
{//一次划分过程 
    int pivot = A[low];
    while (high > low)
    {
        while (high > low && pivot <= A[high])
            high --;
        A[low ++] = A[high];
        while (high > low && pivot >= A[low])
            low ++;
        A[high --] = A[low]; 
    }
    A[low] = pivot;
    return low;
} 

void QuickSort(int A[], int low, int high)
{//采用闭区间 
    int pivotkey;
    if (low < high)
    {
        pivotkey = Partition(A, low, high);
        QuickSort(A, low, pivotkey-1);
        QuickSort(A, pivotkey+1, high);
    }
} 

int main()
{
    int A[] = {5, 2, 9, 7, 1, 0, 6, 8, 4, 3};
    int high = sizeof(A)/sizeof(A[0]) - 1;
    QuickSort(A, 0, high);
    for (int i = 0; i <= high; i ++)
    {
        cout << A[i] << " ";
    }
    
    return 0;
} 

ii沙漠的主页 ii沙漠 | 初学一级 | 园豆:114
提问于:2014-08-19 09:52
< >
分享
最佳答案
0

A[low ++] = A[high];

 

A[low] = A[high];

收获园豆:20
ayiis | 菜鸟二级 |园豆:356 | 2014-08-19 10:19

谢谢。

ii沙漠 | 园豆:114 (初学一级) | 2014-08-19 10:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册