Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

堆疊(計算機概論)

要將堆疊內ACBD(D位於最底)調整成BCDA需要幾個動作?我想要看算的過程

Update:

題目是說需作作幾次取出與壓入?對我想要知道是怎麼做的

答案是8次

3 Answers

Rating
  • 1 decade ago
    Favorite Answer

    please specify:

    (1) the definition of 動作? push(x) and pop()? How about create()?

    (2) the amount of externla memory allowed? Most likely it is 2 and another stack?

    2009-11-26 14:15:07 補充:

    1.

    Define Array XX at size of 4 stack elements;

    2.

    XX[0] = pop();

    // pop out A

    3.

    XX[2] = pop(); // pop out C

    4.

    XX[1] = pop(); //

    pop out B

    5.

    XX[3] = pop(); //

    pop out D – stack is empty

    6.

    Push(XX[0]); //

    push A into stack;

    7.

    Push(XX[3]); //

    push D into stack;

    8.

    Push(XX[2]); //

    push C into stack;

    9.

    Push(XX[1]); //

    push B into stack; stack is [top]BCDA[bottom]

  • 1 decade ago

    千千萬萬不要點回答者 002 九聲長歎 的 link!

    大有問題!!!

    那個程式,他用來答一大堆的問題!!

    不可能有這種萬用程式!

    那裡面也完全沒有和你問的問題相關的東西!!

    小心是新病毒/新木馬!

  • 1 decade ago

    大一生是吧? 這是河內塔,

    只要三列, 不管你要疊幾圈, 只要三列,

    我當年就做 24 圈的(大一就被請去當助教)

    河內塔程式是 Pascal 時代的經典, 去找 Pascal 導論類的書抄吧!

    導論通常都用演算法寫, so 學 C 的你應該看得懂.

Still have questions? Get your answers by asking now.