字符串排列中的两次交换?

时间:2013-12-26 04:13:57

标签: string recursion permutation

有人可以准确地解释为什么我们需要在找到字符串的所有排列的算法中撤消交换?

swap((a+i), (a+j));  // Make a[j] the start of this (sub-)permutation starting at i.
permute(a, i+1, n);  // Find the permuations of a[i+1..n] - and undo them.
swap((a+i), (a+j));  // Undo the swap of a[i] and a[j].

0 个答案:

没有答案