终于搞清了它的过程,但是还是不知道其中编写的奥妙,再仔细想想为什么要这样
#include<iostream.h>
#include<string.h>
void Hanoi(int n,char A,char B,char C);
void main()
{
Hanoi(3,'A','B','C');
}
void Hanoi(int n,char A,char B,char C)
{
if(n==1)
cout<<"Move top disk from peg "<<A<<" to peg "<<C<<endl;
else
{
Hanoi(n-1,A,C,B);
cout<<"Move top disk from peg "<<A<<" to peg "<<C<<endl;
Hanoi(n-1,B,A,C);
}
}