Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

备份代码

  • 生成随机大量数字,并调用排序算法
int main()
{
    const int SIZE = 50;
    vector<int> nums;
    for(int i = 0; i < SIZE; i++){
        nums.push_back(i*(i%3 + 1));
        nums.push_back((-1) * i*(i%3 + 1));
    }
    int t = 20;
    while(t--){
        srand(time(NULL));
        for(int i = 0; i < SIZE; i++){
            int r = (i + rand() % SIZE) % SIZE;
            swap(nums[i], nums[r]);
        }
    }
    
    selectionSort(nums);
    for(auto num: nums) cout<<num<<endl;
    return 0;
}