Support Me...........

Please support me by giving donation

contact: aswinavofficial@gmail.com


Total Pageviews

Monday, September 1, 2014

C++ program to solve Hanoi Tower

/* Tower Of Hanoi */
 #include using namespace std;
 void hanoi(int n);
 void moveTower(int ht, char f, char t, char i); 
 void moveRing(int d, char f, char t); 
 int main() { cout << "How many disks? ";
 int x;
 cin >> x;
 hanoi (x);
 return 0; }
 void hanoi(int n) 
{
 moveTower(n, 'A', 'B', 'C');
 } void moveTower(int ht, char f, char t, char i)
 { if (ht > 0) { moveTower(ht-1, f, i, t);
 moveRing(ht, f, t);
 moveTower(ht-1, i, t, f);
 } } void moveRing (int d, char f, char t)
 { cout << "Move ring " << d << " from ";
 cout << f << " to " << t << endl; } // aiuto

No comments: