Algorithm code: Combination opposite to std::permutation
BenBear
cxj26424@163.com
Thu Apr 21 13:43:00 GMT 2005
Hi, libstdc++-v3
adjust_combination ()
next_combination ()
prev_combination ()
I wrote a algorithm of combination, which is opposite to
std::permutation. It provides three operations, adjust_combination(),
next_combination() and prev_combination(). The next_combination() and
prev_combination() is just like the std::next_permutation() and
std::perv_permutation().
Each operation's arguments are three iterators, first, middle and last.
I treat the range [first, middle) as the elements selected, while the
range [middle, last) are the elements left. The range [first, middle)
is treated in dictionary ordering, like the std::permutation. [middle,
last) is maintained in a special ordering.
A simple example:
select 2 elements from {1, 2, 3, 4}
f m l // f: first, m: middle, l: last
1 2, 3 4
1 3, 4 2
1 4, 3 2
2 3, 4 1
2 4, 3 1
3 4, 2 1
The first two number are the elements selected, in dictionary ordering.
The next combination of {3 4}/{2 1} will be {1 2}/{3 4}.
Ben Bear
-------------- next part --------------
A non-text attachment was scrubbed...
Name: combination.cpp
Type: text/x-c++src
Size: 6009 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20050421/2523046c/attachment.bin>
More information about the Libstdc++
mailing list