Wednesday, 11 September 2013

What does an exclamation mark next to an array mean when used in an if statement? "if (!used[i])"

What does an exclamation mark next to an array mean when used in an if
statement? "if (!used[i])"

I'm trying to understand my professor's code for teaching permutations,
and I don't know what the "(!used[i])" inside an if statement means or
does. Here's the full function, the if statement is within the for loop.
Can anyone explain what it does?
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;
}
}
}

No comments:

Post a Comment