#include
#include
class hanoi
{
int disk;
char beg[4],end[4],aux[4];
public:
void move(int,char[],char[],char[]);
};
void hanoi::move(int disk,char frmtwr[4],char totwr[4],char auxtwr[4])
{
if (disk==1)
{
cout<<”\nMove disk 1 from tower “<<frmtwr<<” to tower “<<totwr;
return;
}
move(disk-1,frmtwr,auxtwr,totwr);
cout<<”\nMove disk “<<disk<<” from tower “<<frmtwr<<” to tower “<<totwr;
move(disk-1,auxtwr,totwr,frmtwr);
return;
}
void main()
{
int n;
hanoi object;
clrscr();
cout<<”Tower Of Hanoi\n”;
cout<<”Let the towers be BEG,AUX & END\n”;
cout<<”Enter the number of disks: “;
cin>>n;
object.move(n,”BEG”,”END”,”AUX”);
getch();
}
No comments:
Post a Comment