#include<iostream>
#include<vector>
#include<stack>
#include<string>
#include <stdio.h>
#include <stdlib.h>
using namespace::std;
class Solution {
public:
Solution():n(2)
{
stack<int> tower1;
stack<int> tower2;
stack<int> tower3;
hanoi.push_back(tower1);
hanoi.push_back(tower2);
hanoi.push_back(tower3);
for(int i = n; i > 0 ; i--)
{
hanoi[0].push(i);
}
}
void print(stack<int> tower)
{
while(tower.size() != 0)
{
cout<<tower.top()<<endl;
tower.pop();
}
}
void move(stack<int>& start, stack<int>& end, stack<int>& buffer, int layer)
{
int tmp = 0;
if(layer > 0)
{
// cout<<"layer: "<<layer<<endl;
move(start, buffer, end, layer - 1);
tmp = start.top();
// cout<<"TMP: "<<tmp<<endl;
start.pop();
end.push(tmp);
move(buffer, end, start, layer - 1);
}
}
void doMove()
{
print(hanoi[0]);
move(hanoi[0], hanoi[2], hanoi[1], n);
print(hanoi[2]);
}
private:
vector<stack<int>> hanoi;
int n;
};
终于圆了大一C语言课的梦,征服了汉诺塔