Re: [问题] 100台联大系统堆叠问题

楼主: forris (科科...)   2012-06-16 00:05:19
※ 引述《lkjh775533 (考得火热)》之铭言:
: 5.What is the top element of Stack S after execution of the pseudocode
: program on the below?
: Stack(S);//create a stack S
: Queue(Q);//create a queue Q
: Push(S,1);Push(S,2);
: Push(S,3);Push(S,4);
堆叠程式跑完是这样 (上方为 top)
│ │
|4 │
|3 │
|2 │
|1 │
└──┘
: Enqueue(Q,5);Enqueue(Q,6);
加入 queue (上方为 front,下方为 rear)
│ │ │ │
|4 │ │5 │
|3 │ │6 │
|2 │ │ │
|1 │ │ │
└──┘
: for(i=1 to 4){
: x=Pop(S);
: Enqueue(Q,x);
: }
把 stack 里的东西 pop 出来,依序 enqueue 到 queue 里
│ │
│5 │
│6 │
│4 │
│3 │
│2 │
│1 │
│ │
: for(i=1 to 6){
: x=Dequeue(Q);
: Push(S,x);
: }
再把 queue 里的东西依序 dequeue 出来,push 到 stack 中
│ 1 │
│ 2 │
│ 3 │
│ 4 │
│ 6 │
│ 5 │
└──┘
最上面的元素不就是 1
: a.4 b.3 c.2 d.1 e.None of the above
: 我认为答案的关键在top element of Stack
: 另一题也是台联100
: 25.A stack is initially empty, then the following commands are performed:
: push 5
: push 7
: pop
: push 10
: push 5
: pop
: Which of the following is correct stack after those commands(assume the top
: of the stack is on the left)?
: 我认为答案的关键在也top element of Stack
: 所以能否请版上高手讲解一下何谓堆叠顶端?如何去判别?谢谢大家!!
: ps:A4的同志加油 实力才是唯一的靠山!!
作者: lkjh775533 (考得火热)   2012-06-16 20:04:00
感谢f大热心解答,想再问f大对于25题的意见。

Links booklink

Contact Us: admin [ a t ] ucptt.com