The following recursive program segment is written in C language.
Write the output if it is called with the instruction xbox (3, ‘A’, ‘B’,
‘C’).
void xbox (int n, char x, char y, char z)
{
if (n > 0 ) {
printf(“%c %c %c \n”, x, y, z);
xbox (n-1 , x, z, y);
xbox (n-1 , y, x, z);
}
}
解:
n = 3 A B C
n = 2 A C B
n = 1 A B C
n = 1 C A B
n = 2 B A C
n =1 B C A
n =1 A B C