How do I add a linked list or convert it to a linked list using a stack function
#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.
精彩评论