Skip to content

Stack

storing

Level 1 of 3

Also called Last in, first out.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from stack's own run on the numbers shown.

choose one

question 1

An empty stack is given 53, 65, -, 84, 98, -. Each number is put on, and each dash takes the top off. What does the pile hold then, bottom first?

the answer, and why

the answer is C

65 goes on 53 and comes straight back off. Then 84 and 98 go on, and the last take takes 98, the top.

if you chose another

  • That keeps 65, but the first take takes 65, the top then.
  • That takes 53, the bottom. A take only ever takes the top.
  • That misses the first take, which takes 65 off.

new numbersthe test page's numbers

question 2

How many numbers come back from an empty stack given 40, 80, -, -, -, 9, -?

the answer, and why

the answer is D

The first two takes give back 80, then 40. The third finds the pile empty and gives nothing. The last gives back 9.

if you chose another

  • That counts every dash, but the third take finds the pile empty.
  • That stops before 9 goes on and comes back.
  • That counts every operation, the puts too.

new numbersthe test page's numbers