![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
STL使用
NoBlackstone
硕士研究生,期间的研究方向是人工智能的预测算法,C++后端服务器开发的有关工作,所以会在这里分享一些自己的学习笔记,觉得有用的话可以收藏点赞,若有问题欢迎在评论区批评指正。
展开
-
STL中sort函数的自定义排序
1、默认排序 默认是升序排序less<typeName>(),也可以使用降序排序greater<typeName>() //实例1 vector<int> vec{2, 1, 3, 4, 6, 5}; sort(vec.begin(), vec.end()); for (int v : vec) { cout << v << " "; } cout << endl; /* 输出为 1 2 3 4 5 6 */ //实例2 vec.原创 2021-11-16 15:02:29 · 745 阅读 · 0 评论 -
STL中priority_queue的自定义排序
1、默认排序 使用默认定义优先队列,将以最大堆的形式进行存储; //实例 vector<int> nums{1, 2, 3, 4, 5}; priority_queue<int> heap; for (int num : nums) { heap.emplace(num); } while (!heap.empty()) { cout << heap.top() << " "; heap.pop(); } /* 输出为 6 5 4 3 2 1 */.原创 2021-10-25 11:16:16 · 288 阅读 · 1 评论