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); }
def stackPopOp(state): values = state.values if (values.length == 0): reportNotFound() return top = (values.length - 1) probeSlot(top) removed = values[top] values.length = top popValue(top, removed) finish(values.length)
#include <vector> #include <algorithm> void stackPopOp(int state) { auto values = state.values; if((values.length == 0)) { reportNotFound(); return; } auto top = (values.length - 1); probeSlot(top); auto removed = values[top]; values.length = top; popValue(top, removed); finish(values.length); }
public void stackPopOp(int state) { var values = state.values; if((values.length == 0)) { reportNotFound(); return; } var top = (values.length - 1); probeSlot(top); var removed = values[top]; values.length = top; popValue(top, removed); finish(values.length); }
#include <stdio.h> void stackPopOp(int state) { var values = state.values; if((values.length == 0)) { reportNotFound(); return; } var top = (values.length - 1); probeSlot(top); var removed = values[top]; values.length = top; popValue(top, removed); finish(values.length); }