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
swap.cpp
Go to the documentation of this file.
1
29
#include <algorithm>
// for copy, iter_swap
30
#include <iostream>
// for cout, endl
31
#include <iterator>
// for ostream_iterator
32
#include <vector>
// for vector
33
34
int
main
()
35
{
36
typedef
std::ostream_iterator<int, char, std::char_traits<char> >
Iter
;
37
38
const
int
a
[] = { 6, 7, 8, 9, 10, 1, 2, 3, 4, 5 };
39
40
// Set up a vector.
41
std::vector<int, std::allocator<int> >
v
(
a
,
a
+
sizeof
a
/
sizeof
*
a
);
42
43
// Output original vector.
44
std::cout <<
"For the vector: "
;
45
std::copy (
v
.begin (),
v
.end (),
Iter
(std::cout,
" "
));
46
47
// Swap the first five elements with the last five elements.
48
std::swap_ranges (
v
.begin (),
v
.begin () + 5,
v
.begin () + 5);
49
50
// Output result.
51
std::cout <<
"\n\nSwaping the first five elements "
52
"with the last five gives: \n "
;
53
54
std::copy (
v
.begin (),
v
.end (),
Iter
(std::cout,
" "
));
55
56
// Now an example of iter_swap -- swap first and last elements.
57
std::iter_swap (
v
.begin(),
v
.end () - 1);
58
59
// Output result.
60
std::cout <<
"\n\nSwaping the first and last elements gives: \n "
;
61
std::copy (
v
.begin (),
v
.end (),
Iter
(std::cout,
" "
));
62
63
std::cout << std::endl;
64
65
return
0;
66
}
v
#define v
Definition
17.names.cpp:138
a
#define a
Definition
17.names.cpp:109
Iter
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition
alg7.cpp:64
main
int main()
Definition
swap.cpp:34
Generated by
1.9.8