Stack Pop

Remove and return the element on top of a LIFO stack in constant time.

Time O(1) Space O(1) Stack pop

How it works

Remove and return the element on top of a LIFO stack in constant time.

Implementation

function stackPopOp(state) {
  const values = state.values;
  if (values.length === 0) {
    reportNotFound();
    return;
  }
  const top = values.length - 1;
  probeSlot(top);
  const removed = values[top];
  values.length = top;
  popValue(top, removed);
  finish(values.length);
}