- 博客(11)
- 收藏
- 关注
原创 C++ sort函数自定义比较函数的效率
本文用于记录实践中遇到的自定义比较函数效率问题,暂不涉及底层原理。——2022.03.01.leetcode question406,重建队列。如果sort函数的比较函数这么写:sort(people.begin(), people.end(), [](const vector<int>& u, const vector<int>& v) { return u[0] < v[0] || (u[0] == v[0] &
2022-03-01 20:49:41
1045
转载 二维vector初始化的几种方法
Fill Constructor:#define M 4#define N 4// one step, recommendedstd::vector<std::vector<int>> matrix(M, std::vector<int>(N, 0));// two stepsstd::vector<int> row(N, 0);std::vector<std::vector<int>> matrix2(M, ro
2022-01-26 14:38:58
5563
原创 C++ move()函数应用场景
场景1:move(obj)函数的功能是把obj当做右值处理,可以应用在对象的移动上。注意,如果仅仅是定义右值引用,那么obj本身不会被移走,在作为参数时会发生obj被移走: string str = "test"; string&& r = move(str); cout<< r <<endl; cout<< str <<endl; string t(r); cout<<
2022-01-06 19:07:00
2512
原创 emplace_back不能取代push_back的情况
1.当直接把构造好的元素放入数组时不能直接使用前者:vector<vector<int>> v;v.push_back({1,2,3}); // OKv.emplace_back({1,2,3}); // error:no matching member function for call to 'emplace_back'v.emplace_back(vector<int>{1,2,3}); // OKv.emplace_back<vector<
2022-01-05 13:22:03
3168
1
转载 C++ priority_queue自定义比较方式
优先队列完整参数:priority_queue<class Type,class Container,class Compare>;推荐Container:vector<Type>默认Compare使用方法:1.less<Type>2.greater<Type>自定义比较函数Compare,可使用两种方法:方法1,写一个比较结构体struct:#include<queue>#include<vect
2022-01-03 11:30:41
2318
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅