大佬们,这题快排可行吗?
查看原帖
大佬们,这题快排可行吗?
856052
116147zqq楼主2022/11/17 20:46
#include <iostream>

using namespace std;
const int N=2000010;
int a[N];
void QuickSort(int a[],int low,int high)
{
    int i=low,j=high;
    int t;
    if(i>=j)
        return;
    int temp=a[low];
    while(i!=j)
    {
        while(a[j]>=temp&&i<j)
            j--;
        while(a[i]<=temp&&i<j)
            i++;
        if(i<j)
            {
                t=a[i];
                a[i]=a[j];
                a[j]=t;
            }
    }
    a[low]=a[i];
    a[i]=temp;
    QuickSort(a,low,i-1);
    QuickSort(a,i+1,high);
}

int main()
{
    int m,n,i;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a[i];
    }
    QuickSort(a,0,m-1);
    for(i=0;i<m;i++)
    {
        cout<<a[i]<<' ';
    }
    return 0;
}

2022/11/17 20:46
加载中...