Skip to content

Queue: Size

Task: Count how many values are waiting

frontrear275SIZE2kept as a count

What you are watching

A queue does not count its values when asked how many are waiting. It keeps a running total, adding one on every enqueue and subtracting one on every dequeue, so size is read rather than walked. Three arrivals take it to three and one departure takes it back to two, and the answer costs the same whether three values are waiting or three million.