有大佬解释一下hanoi怎么逐层返回的这个代码包含了太多[em08]
#include<stdio.h>void hanoi(int n, char A, char B, char C)
{
if (n == 1)
{
printf("%c -> %c\n", A, C);
}
else
{
hanoi(n - 1, A, C, B);
printf("%c -> %c\n", A, C);
hanoi(n - 1, B, A, C);
}
}
int main()
{
hanoi(2, 'A', 'B', 'C');
return 0;
}