如何在std :: set< int>?中找到最大的int [英] How do I find the largest int in a std::set<int>?
本文介绍了如何在std :: set< int>?中找到最大的int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个std :: set,什么是正确的方法来找到这个集合中最大的int?
I have a std::set, what's the proper way to find the largest int in this set ?
推荐答案
比较器是否正在使用?
对于默认值,这将工作:
For the default this will work:
if(!myset.empty())
*myset.rbegin();
else
//the set is empty
而不是像max_element解决方案的线性。
This will also be constant time instead of linear like the max_element solution.
这篇关于如何在std :: set< int>?中找到最大的int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文