How it works
Remove and return the element at the front of a FIFO queue in constant time.
Implementation
function queueDequeueOp(state) { const values = state.values; const head = state.head; if (head >= values.length) { reportNotFound(); return; } probeSlot(head); const removed = values[head]; state.head = head + 1; dequeueValue(head, removed); finish(values.length - state.head); }
def queueDequeueOp(state): values = state.values head = state.head if (head >= values.length): reportNotFound() return probeSlot(head) removed = values[head] state.head = (head + 1) dequeueValue(head, removed) finish((values.length - state.head))
#include <vector> #include <algorithm> void queueDequeueOp(int state) { auto values = state.values; auto head = state.head; if((head >= values.length)) { reportNotFound(); return; } probeSlot(head); auto removed = values[head]; state.head = (head + 1); dequeueValue(head, removed); finish((values.length - state.head)); }
public void queueDequeueOp(int state) { var values = state.values; var head = state.head; if((head >= values.length)) { reportNotFound(); return; } probeSlot(head); var removed = values[head]; state.head = (head + 1); dequeueValue(head, removed); finish((values.length - state.head)); }
#include <stdio.h> void queueDequeueOp(int state) { var values = state.values; var head = state.head; if((head >= values.length)) { reportNotFound(); return; } probeSlot(head); var removed = values[head]; state.head = (head + 1); dequeueValue(head, removed); finish((values.length - state.head)); }