C Standard Library provides two generated aligned algorithms: next_permutation () and prev_permutation (), but does not provide a standard function that generates a number of groups.
We can easily obtain "combination" from "Arrange" because there is a close relationship between the arrangement and the combination. Take the combination of R elements from n elements, with n! / (R! * (N-r)!)! These combinations can be generated with a full alignment of multiplex {R · 1, (N-R) · 0}, please see the sample program:
#include
INT main () {// From n element, all combinations of R element: // g [o] BCC5 [O] VC7 [x] const INT N = 7; const Int r = 4; //// 0 <= r <= n vector
The above programs are compiled under G 3.2, BCC 5.5.1, VC7, but the dead cycle is running in the VC7 version. Suspected this is the BUG of VC7, so use the following procedure to verify:
#include
Using namespace std;
INT main () {// is compiled by VC7, will die, incredible! // bcc5 [o] g [o] vc7 [x] vector
DO {copy (p.begin (), p.end (), ostream_iterator
It is still a cycle of the VC7 version, which seems to be a bug in the PREV_PERMUTATION () in the VC7. I submitted a bug Report to http://www.dinkumware.com/, the reply obtained was: Our Documentation Points Out, for Both Prev_Permutation andNext_Permutation That No Two Elements May Have EquivalentOrdering.
P.j. Plauger
In the case of the documentation, HTTP: //www.dinkumware.com/ The document has indeed this. In MSDN, I didn't find a similar proposal, I am afraid I can only interpret the update of the MS's documentation too slow.