Monotonic stack and queue