Re: [問題] 100台聯大系統堆疊問題

看板TransCSI作者 (科科...)時間12年前 (2012/06/16 00:05), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《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的同志加油 實力才是唯一的靠山!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.11.133.201

06/16 20:04, , 1F
感謝f大熱心解答,想再問f大對於25題的意見。
06/16 20:04, 1F
文章代碼(AID): #1Fsrr287 (TransCSI)
文章代碼(AID): #1Fsrr287 (TransCSI)