首页 > 其他 > 详细

一个FLAG #17# 测试STL

时间:2020-04-15 10:23:55      阅读:64      评论:0      收藏:0      [点我收藏+]

例子

#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初步

一个FLAG #17# 测试STL

原文:https://www.cnblogs.com/xkxf/p/12694605.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!