Write a program in C Implement an iterative solution to the

Write a program in C++:

Implement an iterative solution to the Towers of Hanoi. (DO NOT USE RECURSION)

If you don\'t know what towers of hanoi is, here is the description:

Once again WRITE PROGRAM IN C++ AND DO NOT USE RECURSION

Solution

void towers(int n, char ea, char gb, char xc)
{
struct stack s;
struct details current;
int flag;
char temp;
s.top=-1;
current.number=n;
current.e=ea;
current.g=gb;
current.x=xc;
while(1){
while(current.number!=1)
{
push(&s,&current);
--current.number;
temp=current.e;
current.e=current.x;
current.x=temp;
}
cout<<\"Move Disc 1 from \"<<current.g<<\" to \"<<current.e<<endl;
popandtest(&s,&current,&flag);
if(flag==1)
return;
cout<<\"Move Disc \"<<current.number<<\" from \"<<current.g<<\" to \"<<current.e<<endl;
--current.number;
temp=current.g;
current.g=current.x;
current.x=temp;
}
}
int main()
{
int N;
cout<<\"Enter the number of disk: \";
cin>>N;
towers(N,\'B\',\'E\',\'A\');
return 0;
}

Write a program in C++: Implement an iterative solution to the Towers of Hanoi. (DO NOT USE RECURSION) If you don\'t know what towers of hanoi is, here is the d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site