使用c ++中的next_permutation()stl在两个数组中进行相同的排列

ka4*_*tik 5 c++ algorithm stl

是否有一种简单的方法可以使next_permutation执行相同的交换两个不同的相同大小的数组,例如,如果我有两个数组a[]={1,2,3,4,5},b[]={12,23,21,2,3} 如果在数组a中的perhtion 1进入第3个位置,那么数组b中的12也应该转到第3个位置.

Ker*_* SB 4

您可以制作辅助索引集:

int a[] = { 1, 2, 3, 4, 5 };
int b[] = { 12, 23, 21, 2, 3 };

std::size_t indices[] = { 0, 1, 2, 3, 4 };
Run Code Online (Sandbox Code Playgroud)

现在对 执行排列indices,然后使用a[indices[i]]b[indices[i]]