主题:大家帮忙看一下
#include"iostream"
#define debug_mode
using namespace std;
void move(char x,char z);
void hanoi(int n,char x,char y,char z);
void main()
{ int num;
cout<<"请输入盘子数:";
cin>>num;
cout<<"按\"汉罗塔\"的规则,把"<<num
<<"个盘子从A针搬到C针的步骤是:"<<endl;
hanoi(num,'A','B','C');
}
void move(char x,char z)
{ static int i;
i++;
cout<<i<<": "<<x<<" → "<<z<<endl;
}
void hanoi(int n,char x,char y,char z)
{ #ifdef debug_mode
cout<<n<<" "<<x<<" "<<y<<" "<<z<<endl;
#endif
if(n==1)
move(x,z);
else{
hanoi(n-1,x,z,y);
move(x,z);
hanoi(n-1,y,x,z);
}
}
我从书上抄的 可老是报错 大家帮忙看看怎么回事
#define debug_mode
using namespace std;
void move(char x,char z);
void hanoi(int n,char x,char y,char z);
void main()
{ int num;
cout<<"请输入盘子数:";
cin>>num;
cout<<"按\"汉罗塔\"的规则,把"<<num
<<"个盘子从A针搬到C针的步骤是:"<<endl;
hanoi(num,'A','B','C');
}
void move(char x,char z)
{ static int i;
i++;
cout<<i<<": "<<x<<" → "<<z<<endl;
}
void hanoi(int n,char x,char y,char z)
{ #ifdef debug_mode
cout<<n<<" "<<x<<" "<<y<<" "<<z<<endl;
#endif
if(n==1)
move(x,z);
else{
hanoi(n-1,x,z,y);
move(x,z);
hanoi(n-1,y,x,z);
}
}
我从书上抄的 可老是报错 大家帮忙看看怎么回事