......................

Towers of Hanoi

Posted by Unknown On Monday, August 23, 2010 0 comments

#include "iostream.h"
#include "conio.h"

void Move(int N,char BEG,char AUX,char END)
{
 if(N > 0)
  {
   Move(N - 1,BEG,END,AUX);
   cout << "\nMove top disk from peg " << BEG << " to peg " << END;
   Move(N - 1,AUX,BEG,END);
  }
}

int main()
{
 int n;
 cout << "How many Disks? ";
 cin >> n;
 Move(n,'A','B','C');
 getch();
 return 0;
}


No comments:

Post a Comment

Leave Feedback about this BLOG