例子

#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;

void fill_random_int(vector<int>& v, int cnt)
{
    v.clear();
    for (int i = 0; i != cnt; ++i) {
        v.push_back(rand());
    }
}

void test_sort(vector<int>& v) 
{
    sort(v.begin(), v.end());
    for (int i = 0; i != v.size() - 1; ++i) {
        assert(v[i] <= v[i + 1]);
    }
} 

int main()
{
    srand(time(NULL));
    
    vector<int> v;
    fill_random_int(v, 1000000);
    test_sort(v);    
    return 0;    
}

// => Process exited after 3.556 seconds with return value 0

参考

[1] 一个FLAG #09# STL初步

相关文章:

  • 2021-06-12
  • 2021-12-26
  • 2021-10-12
  • 2021-11-11
  • 2022-12-23
  • 2021-05-18
  • 2021-09-29
猜你喜欢
  • 2021-11-04
  • 2022-12-23
  • 2021-11-05
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
相关资源
相似解决方案