Skip to content

Queue

storing

Level 1 of 3

Also called First 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 queue's own run on the numbers shown.

choose one

question 1

An empty queue is given 6, 2, -, 9, 4, -. Each number joins, and each dash lets the front one leave. What does the line hold then, front first?

the answer, and why

the answer is A

6 leaves first, the oldest. Then 9 and 4 join behind 2, and the last dash lets 2 leave.

Queue, oldest out. Numbers join at the right end, the back, and leave from the left end, the front.

join 66join 262leave26gives 6join 929join 4294leave942gives 2

Out, in turn: 6, 2.

  • just put in
  • just taken out
Each operation in turn. The line ends holding 9 and 4.

if you chose another

  • That is a stack's answer, where each dash takes the newest. A leave always takes the front.
  • That misses the last leave, which lets 2 go.
  • That reads the line from the back. Front first, 9 leads.

new numbers

question 2

How many numbers leave an empty queue given -, 5, 1, -, -, -, 8, -?

the answer, and why

the answer is B

The first dash finds the line empty. 5 and 1 join and leave in turn. The next dash finds it empty again, then 8 joins and leaves.

Queue, oldest out. Numbers join at the right end, the back, and leave from the left end, the front.

leaveempty, nothing comesjoin 55join 151leave15gives 5leave1gives 1leaveempty, nothing comesjoin 88leave8gives 8

Out, in turn: 5, 1, 8.

  • just put in
  • just taken out
5 dashes. The 1st and the 4th find the line empty, so 3 numbers leave.

if you chose another

  • That counts every dash, but the first and the fourth find the line empty.
  • That counts one of the two dashes that find the line empty.
  • That counts every operation, the joins too.

new numbers