8.2 Stacks
The first two abstract data structures we will explore are stacks and queues, which are often thought of as a pair—like peanut butter and jelly. Why this is so may be more for historical reasons than anything else, because these two structures have quite different behaviors.
A stack is an abstract composite structure in which accesses are made at only one end. You can insert an item as the first one and you can remove the first one. This type of processing is referred to as LIFO, which stands for “last in, first out.” This design models many things in real life, such as a plate holder in a cafeteria: We can take only the top plate. When we do so, the plate below rises to the top so the next person can take one. Canned goods on a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access