how can I find the smallest item in a vector

Discussion in 'C++' started by ken, Feb 21, 2007.

  1. ken

    ken Guest

    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.
    ken, Feb 21, 2007
    #1
    1. Advertising

  2. ken

    ken Guest

    On Feb 20, 8:50 pm, "ken" <> 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
    ken, Feb 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    23,784
  2. Jeremy

    find the smallest integers

    Jeremy, Feb 8, 2007, in forum: Java
    Replies:
    0
    Views:
    365
    Jeremy
    Feb 8, 2007
  3. Code4u
    Replies:
    4
    Views:
    2,644
    Stephen Howe
    Jul 13, 2005
  4. Replies:
    8
    Views:
    1,914
    Csaba
    Feb 18, 2006
  5. Sunny
    Replies:
    7
    Views:
    123
    William James
    Nov 27, 2008
Loading...

Share This Page