how can I find the smallest item in a vector

K

ken

Hi,

Is there a std algorithm which find the smallest item in a vector?
One way to do it is to use the sort algorithm and then get the first
element.
But what if I just care about the smallest, so I don't care if the
rest of the vector is sorted according.

Is there a more efficient solution to my problem?

Thank you.
 
K

ken

Hi,

Is there a std algorithm which find the smallest item in a vector?
One way to do it is to use the sort algorithm and then get the first
element.
But what if I just care about the smallest, so I don't care if the
rest of the vector is sorted according.

Is there a more efficient solution to my problem?

Thank you.

Okay I find a solution:
std::min_element
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top