Anonymous
Anonymous asked in 教育與參考考試 · 1 decade ago

資料結構問題??

q:請以c++設計"河內塔"程式??

很急需要,高手幫幫忙!! (保證點數不會吝嗇給的!!)

2 Answers

Rating
  • Anonymous
    1 decade ago
    Favorite Answer

    #include <stdio.h>

    void hanoi(int n, char A, char B, char C)

    {

    if(n == 1)

    {

    printf("Move sheet %d from %c to %c\n", n, A, C);

    }

    else

    {

    hanoi(n-1, A, C, B);

    printf("Move sheet %d from %c to %c\n", n, A, C);

    hanoi(n-1, B, A, C);

    }

    }

    int main()

    {

    int n;

    printf("請輸入盤數:");

    scanf("%d", &n);

    hanoi(n, 'A', 'B', 'C');

    return 0;

    }

    Source(s): 我有跑過~這應該對~不知道是不是你要的那類型
    • Login to reply the answers
  • Anonymous
    1 decade ago

    推薦你一本書:資料結構應試寶典

    作者:謝樹明著

    裡面有提到~還蠻仔細ㄉ

    • Login to reply the answers
Still have questions? Get your answers by asking now.