Skip to content

平成30年度 秋期 ITパスポート試験 問76

This question's explanation and your answers so far.

問76
頻出度★☆☆

複数のデータが格納されているスタックからのデータの取出し方として, 適切なものはどれか。

出典 平成30年度 秋期 ITパスポート試験 問76
解説

問 76

  • Incorrectア

    Being able to retrieve data at any position regardless of the order it was stored is a feature of data structures with direct indexed access, such as an array. A stack can only ever take from the top, so this is wrong.

  • イ

    正解 A stack is a last-in, first-out (LIFO) data structure. Adding data onto it is called push, and taking data off is called pop; a pop always removes the item on the very top (that is, the most recently pushed, newest data). Therefore choice イ, retrieving the most recently stored data first, is the correct way to take data out. It helps to picture a pile of plates and always taking from the top.

  • Incorrectウ

    Retrieving the earliest stored data first is first-in, first-out (FIFO), which describes a queue. Its retrieval order is the reverse of a stack, so this is wrong.

  • Incorrectエ

    Retrieving items according to the priority of a key each item holds is the idea behind a priority queue. In a stack, retrieval order is determined only by the order of storage, not by priority, so this is wrong.

ここがポイント
  • A stack is last-in, first-out (LIFO). You add items with push, and a pop takes out the most recently pushed, newest data first.
  • For contrast, a queue is first-in, first-out (FIFO). This difference in retrieval order is the key point that distinguishes a stack from a queue.
用語

Your answers