Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > how can I find the smallest item in a vector

Reply
Thread Tools

how can I find the smallest item in a vector

 
 
ken
Guest
Posts: n/a
 
      02-21-2007
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.

 
Reply With Quote
 
 
 
 
ken
Guest
Posts: n/a
 
      02-21-2007
On Feb 20, 8:50 pm, "ken" <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM



Advertisments