Is there a convenient way to find the largest element in a container using STL?
Is there a way to find the largest container within a container using STL? ATM machine, I have this rather naive way of doing it:
int main()
{
std::vector<std::vector<int> > v;
...
unsigned int h = 0;
for (std::vector<std::vector<int> >::iterator i = v.begin(); i != v.end(); ++i) {
if (*i.size() > h) {
h = *i.size();
}
}
}
+1
a source to share
3 answers
You can always use std :: max_element and pass in a custom comparator that compares the size of the two std::vector<int>
as arguments.
+17
a source to share