Deque Push Front

Insert an element at the front of a double-ended queue, shifting existing elements toward the tail.

Time O(n) Space O(n) Deque pushFront

How it works

Insert an element at the front of a double-ended queue, shifting existing elements toward the tail.

Implementation

function dequePushFrontOp(state, value) {
  const values = state.values;
  let i = values.length;
  while (i > 0) {
    probeSlot(i);
    values[i] = values[i - 1];
    i = i - 1;
  }
  values[0] = value;
  enqueueValue(0, value);
  finish(values.length);
}