#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;
}
......................
Labels:
Recursion
No comments:
Post a Comment