40 typedef std::vector<int, std::allocator<int> > IntVec;
41 typedef std::vector<char, std::allocator<char> > CharVec;
44 const IntVec::value_type
a1[] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 };
45 const CharVec::value_type
a2[] =
"abcdefghji";
48 IntVec
m1 (
a1 + 0,
a1 +
sizeof a1 /
sizeof *
a1);
52 CharVec
m2 (
a2 + 0,
a2 +
sizeof a2 /
sizeof *
a2 - 1);
56 std::copy (
m1.begin (),
m1.end (), prev_m1.begin ());
57 std::copy (
m1.begin (),
m1.end (), next_m1.begin ());
58 std::copy (
m2.begin (),
m2.end (), prev_m2.begin ());
59 std::copy (
m2.begin (),
m2.end (), next_m2.begin ());
62 typedef std::less<IntVec::value_type> IntLess;
63 typedef std::less<CharVec::value_type> CharLess;
65 std::prev_permutation (prev_m1.begin (), prev_m1.end (), IntLess ());
66 std::next_permutation (next_m1.begin (), next_m1.end (), IntLess ());
67 std::prev_permutation (prev_m2.begin (), prev_m2.end (), CharLess ());
68 std::next_permutation (next_m2.begin (), next_m2.end (), CharLess ());
72 typedef std::ostream_iterator<IntVec::value_type, char,
73 std::char_traits<char> >
76 typedef std::ostream_iterator<CharVec::value_type, char,
77 std::char_traits<char> >
80 std::cout <<
"Example 1: \n Original values: ";
81 std::copy (
m1.begin (),
m1.end (), IntOSIter (std::cout,
" "));
83 std::cout <<
"\n Previous permutation: ";
84 std::copy (prev_m1.begin (), prev_m1.end (), IntOSIter (std::cout,
" "));
86 std::cout <<
"\n Next Permutation: ";
87 std::copy (next_m1.begin (), next_m1.end (), IntOSIter (std::cout,
" "));
89 std::cout <<
"\n\nExample 2: \n Original values: ";
90 std::copy (
m2.begin (),
m2.end (), CharOSIter (std::cout,
" "));
92 std::cout <<
"\n Previous Permutation: ";
93 std::copy (prev_m2.begin (), prev_m2.end (), CharOSIter (std::cout,
" "));
95 std::cout <<
"\n Next Permutation: ";
96 std::copy (next_m2.begin (), next_m2.end (), CharOSIter (std::cout,
" "));
98 std::cout << std::endl << std::endl;