我试图理解我教授的排列教学代码,但我不知道 if 语句中的“(!used [i])”是什么意思或作用。这是完整的函数,if 语句在 for 循环中。谁能解释它的作用?
void RecursivePermute(int n, int k, int* perm, int* used) {
int i;
// We've filled perm already. Print the corresponding permutation.
if (k == n) {
for (i=0; i<n; i++)
printf("%d ", perm[i]);
printf("\n");
}
// Try each unused number in spot k.
for (i=0; i<n; i++) {
if (!used[i]) { //this if statement is my question
perm[k] = i;
used[i] = 1;
RecursivePermute(n, k+1, perm, used);
used[i] = 0;
}
}
}