max_element

This is a discussion on max_element within the C++ Programming forums, part of the General Programming Boards category; hey i have question, what if in the range i provide to max_element, there are two or more elements equal ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    164

    max_element

    hey i have question, what if in the range i provide to max_element, there are two or more elements equal which are the largest?

    which 1 would it return?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,606
    It returns (an iterator to) the first element in the range that is among the "largest".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    164
    ok ty

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,606
    After you have found the first one, you can then repeatedly use std::find on the rest of the range.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21