递归--汉诺塔

---恢复内容开始---

//n:盘子个数  a,b,c用字符表示三根柱子
void hanoiTower(int n, char a, char b, char c)
{
    static int step = 0;
    if (n == 1)
    {
        cout << ++step<<":  "<<a << "" << c << endl;
        return;
    }
    else
    {
        hanoiTower(n - 1, a, c, b);
        cout << ++step << ":  " << a << "" << c << endl;
        hanoiTower(n - 1, b, a, c);
    }        
}

 

---恢复内容结束---

posted @ 2015-05-09 23:07  wxquare  阅读(128)  评论(0编辑  收藏  举报