如何使用堆栈功能添加链接列表或将其转换为链接列表

时间:2010-11-18 23:57:02

标签: c++

#include<iostream>

class Hanoi {
public:
  Hanoi();
  void solve(int, char, char, char);
};

Hanoi :: Hanoi() {
}

void Hanoi :: solve(int n, char from, char use, char to) {
  if (n > 0) {
    solve(n-1, from, use, to);
    cout << "Move disk " << n << " from " << from << " to " << to << endl;
    solve(n-1, use, to, from);
   }
}

int main(void) {
  Hanoi h;
  int N;
  cout << "Enter number of disks : " << endl;
  cin >> N;
  h.solve(N,'A','B','C');
  cin >> N;
}

1 个答案:

答案 0 :(得分:1)

他想让它迭代。

如果迭代,请查看here以获得答案。