Hi Guys I am faced with a problem on tower of hanoi:
we are given a stack of cylinders of alternate colors stacked over one another alternately.
The job is to separate the two stacks of same colour
I could write the code(algorithm) for a regular tower of hanoi using recursion, but I am not able to figure out this part. Can some one help?
Code for regular hanoi problem:
#include<iostream>
using namespace std;
int count=0;
void hanoi(char a,char b,char c,int x)
{
if(x>1)
{
hanoi(a,c,b,x-1);
hanoi(a,b,c,1);
hanoi(c,b,a,x-1);
}
else
{
cout<<"Move a Disk from "<<a<<" to "<<b<<endl; count++;
}
}
int main()
{
int n;
cout<<"Enter the height of stack";
cin>>n;
hanoi('A','B','C',n);
cout<<"\nNo. of changes done:"<<count;
return 0;
}