find the minimum or maximum value in a column of a two dimensional vector

i want to find the minimum value of a column in a two dimensional vector..
is there an easy way to do that?
a function that does that easy for example..
Last edited on
For a general container like vector, use <algorithm> min_element:
http://www.cplusplus.com/reference/algorithm/min_element/

The example in the link uses an array though. For a vector it would be:
 
min_element(v.begin(), v.end(), less);  // less is < 


If you use a specialized container like valarray, it has a max() member function.
Again, it depends on how your 2D vector is set up.

If the inner vectors represent columns, the above will work.
If the inner vectors represent rows, it won't. You'll have to
write something on your own in that case. Don't be lazy :)
Last edited on
ok i have done it in my way..
i ask because i dont know whech are the already functions of the vector..

thank you..!
Oops, I didn't even notice that you said columns. If each inner vector is a row, then you pretty much have to iterate over each vector yourself. If you want the min_element and such of a single vector, then I would definitely recommend using STL algorithms or member functions where you can. It is generally much less error prone. Just look up vector, valarray, and algorithm on this site to see what is available.
Topic archived. No new replies allowed.