【C++】线性时间选择

#include 
#include 
using namespace std;

void swap(vector& nums, int a, int b)
{
    int temp = nums[a];
    nums[a] = nums[b];
    nums[b] = temp;
}

int linear_select(vector& nums, int begin, int end, int target)
{
    int i = begin;
    int j = end;
    int pivot = begin;

    while(i=nums[pivot]){
            j--;
        }
        while(i array1 = {1,5,4,3,2,9,8,6,7,0};
    vector array2 = {1,2,3,4,5,6,7,8,9,10};

    int ans1 = linear_select(array1, 0, array1.size()-1, 5);
    int ans2 = linear_select(array2, 0, array2.size()-1, 5);

    cout << ans1 << endl << ans2 << endl;

    return 0;
}

你可能感兴趣的:(算法设计与分析,c++,算法,数据结构)