A LIFO structure — push adds to the top, pop removes the top, peek inspects it. All O(1).
A LIFO structure — push adds to the top, pop removes the top, peek inspects it. All O(1).
Time complexity: O(1). Space complexity: O(n).
Use the interactive visualizer above to run Stack on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.