STL & Generating exponents, permutations, arrangements, and combinations

Discussion in 'C++' started by Alex Vinokur, May 13, 2004.

  1. Alex Vinokur

    Alex Vinokur Guest

    Alex Vinokur, May 13, 2004
    #1
    1. Advertising

  2. Alex Vinokur

    Tim Love Guest

    "Alex Vinokur" <> writes:

    >Does STL contain algorithms which generate (enable to generate) exponents, permutations, arrangements, and combinations for any
    >numbers and words?


    exponents?

    Here's a quickie example of permutations that I had lying around. See the
    doc for details.



    #include <vector> //for vector
    #include <functional> //for less
    #include <iostream>
    using namespace std;
    int main()
    {
    char a2[] = "abcdefghij";
    vector<char> m2(a2, a2+10);
    vector<char> next_m2((size_t)10);

    next_m2=m2;
    next_permutation(next_m2.begin(),
    next_m2.end(),less<int>());

    cout << "Original values: ";
    copy(m2.begin(),m2.end(),
    ostream_iterator<char>(cout," "));
    cout << endl;

    cout << "Next Permutation: ";
    copy(next_m2.begin(),next_m2.end(),
    ostream_iterator<char>(cout," "));
    cout << endl << endl;

    return 0;
    }
    Tim Love, May 13, 2004
    #2
    1. Advertising

  3. Alex Vinokur

    Alex Vinokur Guest

    "Tim Love" <> wrote in message news:c7vu3k$5hi$...
    > "Alex Vinokur" <> writes:
    >
    > >Does STL contain algorithms which generate (enable to generate) exponents, permutations, arrangements, and combinations for any
    > >numbers and words?

    >
    > exponents?
    >

    [snip]

    See http://www.saliu.com/permutations.html
    -------------------------------------------------
    An example of exponents (N=3, M=3): 111,112,113,121,122,123,131,132, etc. (a total of 27 sets).
    An example of permutations (for N = 3): 1 2 3, 1 3 2, 2 1 3, 2 3 1, 3 1 2, 3 2 1.
    An example of arrangements (for N = 3, M = 2): 1 2, 1 3, 2 1, 2 3, 3 1, 3 2.
    An example of combinations (for N = 3, M = 2): 1 2, 1 3, 2 3.
    -------------------------------------------------

    --
    Alex Vinokur
    mailto:
    http://mathforum.org/library/view/10978.html
    Alex Vinokur, May 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jose luis fernandez diaz

    Combinations/permutations algorithm in C++

    jose luis fernandez diaz, Apr 13, 2004, in forum: C++
    Replies:
    6
    Views:
    14,098
    Leor Zolman
    Apr 13, 2004
  2. Jeff Kish

    permutations and combinations

    Jeff Kish, Mar 7, 2005, in forum: C++
    Replies:
    9
    Views:
    2,266
    DHOLLINGSWORTH2
    Mar 11, 2005
  3. Replies:
    6
    Views:
    446
  4. Seth Leija

    Combinations or Permutations

    Seth Leija, Sep 20, 2010, in forum: Python
    Replies:
    4
    Views:
    263
    Raymond Hettinger
    Sep 21, 2010
  5. Peter Ensch
    Replies:
    5
    Views:
    196
Loading...

Share This Page