permute or next_permutation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littlecompiler
    New Member
    • Mar 2012
    • 2

    permute or next_permutation

    I have a program that I am to use permute to get all permuation of the numbers {0-9}. I have can do this with next_perumation but that starts on the right and moves to the left. I would like to start on the left and move to the right because I need just the firts 7 numbers ( to check a math problem). I was given the code

    Code:
    void permute (int v[], int curr )
    {
       if ( curr >= MAX )
         checkit(v);
       else
      for ( i = curr; i < MAX; i++ )
     { 
      swap (v[i],v[curr]) // interchange the thing at  location i with the value at curr
      permute(v,curr + 1);
    swap (v[curr], v[i]) 
    } 
    } // permute
    but when I run if I add a cout I do not get the permutations. Will this work or is there a way to use next_permutatio n that will start on the left side?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    next_permutatio n needs the begin and end of the range. You supplu this using bidirectional iterators. You need the range 0-7 so supply iterators that point to 0 and 8.

    That should give you what you want.

    Comment

    Working...