++


min_element()


template< class ForwardIterator >

ForwardIterator

min_element( ForwardIterator first,

ForwardIterator last );

 

template< class ForwardIterator, class Compare >

ForwardIterator

min_element( ForwardIterator first,

ForwardIterator last, Compare comp );

max_element() , , , [first,last). , ;   comp.

// max(), min(), max_element(), min_element()

 

#include <algorithm>

#include <vector>

#include <iostream.h>

int main()

{

int ia[] = { 7, 5, 2, 4, 3 };

const vector< int, allocator > ivec( ia, ia+5 );

int mval = max( max( max( max(ivec[4],ivec[3]),

ivec[2]),ivec[1]),ivec[0]);

// : max() : 7

cout << " max() : "

<< mval << endl;

 

mval = min( min( min( min(ivec[4],ivec[3]),

ivec[2]),ivec[1]),ivec[0]);

// : min() : 2

cout << " min() : "

<< mval << endl;

vector< int, allocator >::const_iterator iter;

iter = max_element( ivec.begin(), ivec.end() );

 

// : max_element() : 7

cout << " max_element() : "

<< *iter << endl;

iter = min_element( ivec.begin(), ivec.end() );

 

// : min_element() : 2

cout << " min_element() : "

<< *iter << endl;

}




- -  - -  - -