GCSE Link: None
A stack is a static abstract data type which stores a sequence of items.
But while queues use first in first out (FIFO), stacks use last in first out (LIFO).
These are the main operations on a stack:
push: adds an item to the top of the stackpeek: returns the top item without removing itpop: removes and returns the top item from the stackempty: checks if there are no items on the stackfull: checks if there is no more space on the stack
Stacks are generally depicted vertically, and we use the terms "bottom" and "top" of the
stack to mean the start and end of the underlying array.
One common use of stacks is the call stack, which is explained in 9.07 (Recursion).
What are some other uses of stacks?
E.g., for browser histories (in the back button), or for undo sequences.