Stack Push

Add an element to the top of a LIFO stack in constant time.

Time O(1) Space O(n) Stack push

How it works

Add an element to the top of a LIFO stack in constant time.

Implementation

function stackPushOp(state, value) {
  const values = state.values;
  const top = values.length;
  probeSlot(top);
  values[top] = value;
  pushValue(top, value);
  finish(values.length);
}