Deque Pop Front

Remove and return the element at the front of a double-ended queue, shifting remaining elements toward the head.

Time O(n) Space O(1) Deque popFront

How it works

Remove and return the element at the front of a double-ended queue, shifting remaining elements toward the head.

Implementation

function dequePopFrontOp(state) {
  const values = state.values;
  const n = values.length;
  if (n === 0) {
    reportNotFound();
    return;
  }
  probeSlot(0);
  const removed = values[0];
  let i = 0;
  while (i < n - 1) {
    values[i] = values[i + 1];
    i = i + 1;
  }
  values.length = n - 1;
  dequeueValue(0, removed);
  finish(values.length);
}