Same permutations in two arrays using next_permutation() stl in c++

algorithm, c++, stl

Solution

You can make an auxiliary 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 the permutations on `indices`, and then use `a[indices[i]]` and `b[indices[i]]`.

Problem

Is there is a easy way to make next_permutation to perform same set of swaps two different arrays of same size for example if i have two arrays `a[]={1,2,3,4,5}` and `b[]={12,23,21,2,3}` if after permution 1 in array a goes to 3rd position then 12 in array b should also go to 3rd position.

Original source