Is there an easy way to do next_permutation to perform the same set of swaps of two different arrays of the same size, for example, if I have two arrays a[]={1,2,3,4,5}and b[]={12,23,21,2,3} if after permutation 1 in the array a goes to the 3rd position, then 12 in the array b should also go to the third position .
a[]={1,2,3,4,5}
b[]={12,23,21,2,3}
You can create an additional index set:
int a[] = { 1, 2, 3, 4, 5 }; int b[] = { 12, 23, 21, 2, 3 }; std::size_t indices[] = { 0, 1, 2, 3, 4 };
Now perform permutations on indices, and then use a[indices[i]]and b[indices[i]].
indices
a[indices[i]]
b[indices[i]]
, std:: next_permutation ( stl). , ? . ,
N, next_permutation N! . , false.
, " ", , .
:
int a[] = { 1, 2, 4, 3 }; int b[] = { 11, 12, 14, 13 };
, .