开发者

How do I add a linked list or convert it to a linked list using a stack function

开发者 https://www.devze.com 2023-01-26 08:20 出处:网络
#include<iostream> class Hanoi { public: Hanoi(); void solve(int, char, char, char); }; Hanoi :: Hanoi() {
#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-开发者_如何学Python1, 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;
}


He wants to make it iterative.

Look here for an answer if iterative.

0

精彩评论

暂无评论...
验证码 换一张
取 消