Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
examples
manual
max_elem.cpp
Go to the documentation of this file.
1
29
#include <algorithm>
// for max_element
30
#include <functional>
// for less
31
#include <iostream>
// for cout, endl
32
#include <vector>
// for vector
33
34
35
int
main
()
36
{
37
typedef
std::vector<int, std::allocator<int> >
Vector
;
38
typedef
Vector::iterator
Iterator
;
39
40
const
Vector::value_type
d1
[] = { 1, 3, 5, 32, 64 };
41
// Set up vector.
42
Vector
v1
(
d1
+ 0,
d1
+
sizeof
d1
/
sizeof
*
d1
);
43
44
// Find the largest element in the vector.
45
Iterator
it1 = std::max_element (
v1
.begin (),
v1
.end ());
46
47
// Find the largest element in the range from
48
// the beginning of the vector to the 2nd to last.
49
Iterator
it2 = std::max_element (
v1
.begin (),
v1
.end () - 1,
50
std::less<int>());
51
52
// Find the smallest element.
53
Iterator
it3 = std::min_element (
v1
.begin (),
v1
.end ());
54
55
// Find the smallest value in the range from
56
// the beginning of the vector plus 1 to the end.
57
Iterator
it4 = std::min_element (
v1
.begin () + 1,
v1
.end (),
58
std::less<int>());
59
60
std::cout << *it1 <<
" "
<< *it2 <<
" "
61
<< *it3 <<
" "
<< *it4 << std::endl;
62
63
return
0;
64
}
Iterator
InputIter< UserClass > Iterator
Definition
0.inputiter.cpp:83
d1
#define d1
Definition
17.names.cpp:228
v1
#define v1
Definition
17.names.cpp:245
Vector
std::vector< UserClass, std::allocator< UserClass > > Vector
Definition
23.vector.capacity.cpp:43
main
int main()
Definition
max_elem.cpp:35
InputIter
Definition
rw_alg_test.h:379
Generated by
1.9.8