Reputation: 9798
Is there a way finding largest container inside a container using STL? ATM, I have this rather naïve 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();
}
}
}
Upvotes: 1
Views: 311
Reputation: 36429
You can always use std::max_element and pass a custom comparator that compares the size of two std::vector<int>
as arguments.
Upvotes: 17
Reputation: 46770
You could use quick select, and then select the value on the extreme end:
Upvotes: 0
Reputation: 6649
Have you considered sorting the container using the STL sort methods?
Upvotes: 0