Find another example of Hanoi Towers on C++
================================
/**************************************************************************
-> This C++ program is to solve the towers of hanoi problem.
-> Implemented using recursion.
-> Works in Microsoft VC++ 6.0 , windows xp.
-> Header files used 1)iostream.h
***************************************************************************/
#include<iostream.h>
void move(int n,char *s,char *i,char *d)
// s stands for source tower
// d stands for destination tower
// i stands for intermediate tower
{
if(n>0)
{
move(n-1,s,d,i);
// move n-1 disks from source to intermediate tower
cout<<”disk “<<n<<” is moved from “<<s<<” to “<<d<<endl;
// move the disk from to source to destination
move(n-1,i,s,d);
// move n-1 disks from intermediate to destination
}
}
void main()
{
cout<<”\n**********************************************************\n”;
cout<<”This C++ program is to solve the towers of hanoi problem”;
cout<<”\n**********************************************************\n”;
cout<<”Enter the no. of disks “;
int n;
cin>>n;
move(n,”source tower”,”intermediate tower”,”destination tower”);
}
==============================================
sourse blog - http://ds4beginners.wordpress.com/2006/12/21/towers-of-hanoi/
================================
/**************************************************************************
-> This C++ program is to solve the towers of hanoi problem.
-> Implemented using recursion.
-> Works in Microsoft VC++ 6.0 , windows xp.
-> Header files used 1)iostream.h
***************************************************************************/
#include<iostream.h>
void move(int n,char *s,char *i,char *d)
// s stands for source tower
// d stands for destination tower
// i stands for intermediate tower
{
if(n>0)
{
move(n-1,s,d,i);
// move n-1 disks from source to intermediate tower
cout<<”disk “<<n<<” is moved from “<<s<<” to “<<d<<endl;
// move the disk from to source to destination
move(n-1,i,s,d);
// move n-1 disks from intermediate to destination
}
}
void main()
{
cout<<”\n**********************************************************\n”;
cout<<”This C++ program is to solve the towers of hanoi problem”;
cout<<”\n**********************************************************\n”;
cout<<”Enter the no. of disks “;
int n;
cin>>n;
move(n,”source tower”,”intermediate tower”,”destination tower”);
}
==============================================
sourse blog - http://ds4beginners.wordpress.com/2006/12/21/towers-of-hanoi/