测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A27065. 关于下述C++代码的快速排序算法,说法错误的是( )。int randomPartition(std::vector<int>& arr, int low, int high){ int random=low+rand()%(high-low+1); std::swap(arr[random],arr[high]); int pivot = arr[high]; int i=low-1; for…

单选题 困难

题目描述

关于下述C++代码的快速排序算法,说法错误的是(    )。

int randomPartition(std::vector<int>& arr, int low, int high){
    int random=low+rand()%(high-low+1);
    std::swap(arr[random],arr[high]);

    int pivot = arr[high];
    int i=low-1;

    for(int j=low;j<high; j++){
        if(arr[j]<= pivot){
            i++;
            std::swap(arr[i], arr[j]);
        }
    }
    std::swap(arr[i + 1], arr[high]);
    return i +1;
}
void quicksort(std::vector<int>& arr,int low, int high){
    if(low<high){
        int pi =randomPartition(arr,low, high);

        quicksort(arr,low,pi-1);
        quicksort(arr,pi +1,high);
    }
}

选项(单选)

上一题 下一题