c++ - Permutations of multiple ranges of numbers -


i need generate permutations multiple ranges of numbers in array.

using namespace std;  int generatepermutations(vector<int> &myvector, vector<vector<int> > &swappable) {     int = 0, s = 0;     (s = 0; s < swappable.size(); s++) {         {             (i = 0; < myvector.size(); i++) {                 printf("%i ", myvector[i]);             }             printf("\n");             swappable.pop_back();             generatepermutations(myvector, swappable);         } while (next_permutation(myvector.begin()+swappable[s][0],                 myvector.begin()+swappable[s][1]));     } }  int main() {     vector<int> myarray;     myarray.resize(6);     myarray[0] = 0;     myarray[1] = 1;     myarray[2] = 2;     myarray[3] = 3;     myarray[4] = 4;     myarray[5] = 5;      // swappable positions (0 - first, 1 - last)     vector<vector<int> > swappable;     swappable.resize(2);     swappable[0].resize(2);     swappable[0][0] = 1; swappable[0][1] = 3;     swappable[1].resize(2);     swappable[1][0] = 4; swappable[1][1] = 6;     generatepermutations(myarray, swappable);      return 0; } 

the example above should generate this:

0 1 2 3 4 5 0 2 1 3 4 5 0 1 2 3 5 4 0 2 1 3 5 4 

but generates this:

0 1 2 3 4 5 0 1 2 3 4 5 

i take swappable set of ranges may swapped? [[1, 3], [4, 6]] means in [1, 3) (indexes 1 , 2) can swapped around in range, , [4, 6)? true ranges never overlap?

how look:

typedef vector<vector<int> >::const_iterator swappableiter; void generatepermutations(vector<int> &data,                           swappableiter begin, swappableiter end) {   if (begin == end) {     print(data);   }   else {     vector<int>::iterator start = data.begin() + (*begin)[0],       stop = data.begin() + (*begin)[1];     sort(start, stop);     {       generatepermutations(data, begin + 1, end);     } while (next_permutation(start, stop));   } } 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -