为啥我的快速排序一直过不了呀,有没有大佬看一下
查看原帖
为啥我的快速排序一直过不了呀,有没有大佬看一下
504141
it饼干楼主2021/4/1 08:59
#include<iostream>

using namespace std;


int partien(int l[],int low,int high){
    int pivot;
    pivot=l[low];
    while (low<high)
    {
        while (low<high&&l[high]>=pivot) high--;
        l[low]=l[high];
        while(low<high&&l[low]<=pivot) low++;
        l[high]=l[low];
    }
    l[low]=pivot;
    return low;
}

void quick_sort(int l[],int low,int high){
    if(low<high)
    {
        int pivotdir =partien(l,low,high);
        partien(l,low,pivotdir-1);
        partien(l,pivotdir+1,high);
    }
}
int main(){
    int len;
    cin>>len;
    int l[len];
    for(int i=0;i<len;i++){
        cin>>l[i];
    }
    quick_sort(l,0,len-1);
    for(int i=0;i<len;i++){
        cout<<l[i]<<" ";
    }
}

2021/4/1 08:59
加载中...