卷別
資料結構及演算法
選擇國立政治大學 2026 · 考試 · 第 9 題
考科資料結構
(5%) Suppose we have a queue Q containing the sequence 1, 2, 3, 4, 5. We also have an empty stack S. The only allowable operations are:
- Dequeue an element from Q and print it.
- Dequeue an element from Q and push it onto S.
- Pop an element from S and print it.
Which of the following permutations is impossible to generate as an output sequence?
- (A)1, 5, 4, 3, 2
- (B)3, 4, 5, 2, 1
- (C)1, 3, 2, 5, 4
- (D)4, 3, 1, 2, 5