//递归实现汉诺塔 //devcpp4.9.9.2环境//2006 06 10 //使用系统的运行时栈#include <cstdlib>#include <iostream>using namespace std;void hanoi(int n,char a,char b,char c){ if(n==1) cout<<n<<" "<<a<<" "<<c<<endl; else { hanoi(n-1,a,c,b); cout<<n-1<<" "<<a<<" "<<c<<endl; hanoi(n-1,b,a,c); }} int main(int argc, char *argv[]){ hanoi(3,'x','y','z'); system("PAUSE"); return EXIT_SUCCESS;}

评论