请问关于汉诺塔,如何显示最终的结果,而不是步骤
网上找到的都是移动步骤,如果想看运行后的结果,比如在数组C中的排列顺序,而不是具体的移动过程,请问该如何编写。谢谢!
#include<iostream> #define PAN 3; using namespace std; void move(int a[], int b[]) { int i, j; i = 3-1; j = 3-1; if (a[i]!=0) i--; if (b[j]!=0) j--; b[j] = a[i+1]; a[i+1] = 0; } void hanoi(int n, int A[], int B[], int C[]) { if (n == 1) move(A, C); else { hanoi(n - 1, A, B, C); move(A, C); hanoi(n - 1, B, A, C); } } int main() { int aa[3]; int bb[3] = {0}; int cc[3] = {0}; int i, j; for (i = 0; i < 3; i++) aa[i] = i + 1; hanoi(3, aa, bb, cc); for (j = 0; j < 3; j++) cout <<cc[j] << " "; cout << endl; return 0; }