#include <iostream>
using namespace std;
void hanoi(int n, char p1, char p2, char p3){
static int row = 0;
if(n==1){
cout<<(++row)<<" "<<p1<<"--------->"<<p3<<endl;
}
else{
hanoi(n-1, p1, p3, p2);
cout<<(++row)<<" "<<p1<<"--------->"<<p3<<endl;
hanoi(n-1, p2, p1, p3);
}
}
int main(){
hanoi(4, 'A', 'B', 'C');
return 0;
}
I cannot figure out the second output........why the follow output is 2 A----->c....
my answer is C----->B
No comments:
Post a Comment