# Include <iostream>
# Include <cstring>
Using namespace STD;
Char chars [] = {'A', 'B', 'C '};
Char result [3];
Int flag [3]; // used to mark whether it has been used
Int Len;
// Note that for printing, this function must accept an array of results to record that the character is put in each recursion.
Void show (INT index)
{
Int I;
For (I = 0; I <Len; I ++)
Cout <result [I] <"";
Cout <Endl;
}
Void DFS (INT index)
{
Int I;
If (Index = Len)
Show (LEN); // locate the result and print it
For (I = 0; I <Len; I ++)
If (! Flag [I]) // never used
{
Flag [I] = 1; // mark as used
Result [Index] = chars [I]; // enter the result of this query
DFS (index + 1); // find the next
Flag [I] = 0; // backtracking
}
// When the function comes out of the for loop, it proves that all the possibilities of the current one have been found, and the previous recursion will be returned.
}
Int main ()
{
Memset (flag, 0, sizeof (FLAG ));
Len = sizeof (chars)/sizeof (char );
DFS (0 );
Return 0;
}
Full DFS Arrangement