Queue Dequeue

Remove and return the element at the front of a FIFO queue in constant time.

Time O(1) Space O(1) Queue dequeue

How it works

Remove and return the element at the front of a FIFO queue in constant time.

Implementation

function queueDequeueOp(state) {
  const values = state.values;
  const head = state.head;
  if (head >= values.length) {
    reportNotFound();
    return;
  }
  probeSlot(head);
  const removed = values[head];
  state.head = head + 1;
  dequeueValue(head, removed);
  finish(values.length - state.head);
}