Stacks
Chapter 5, Stacks and Queues, focused on stacks and queues. Now, let’s recap a stack, which is representative of limited access data structures. This name means that you cannot access every element from the structure. So, the way of getting elements is strictly specified. In the case of a stack, you can only add a new element at the top (the push operation) and get an element by removing it from the top (the pop operation). For this reason, a stack is consistent with the LIFO principle, which means Last-In First-Out. The built-in implementation as the Stack
class is available, as well.
The illustration of a stack is shown as follows:
Figure 10.4 – Illustration of a stack
A stack has many real-world applications. One of the mentioned examples is related to a pile of many plates, each placed on top of the other. You can only add a new plate at the top of the pile, and you can only get a plate from the top of the pile. You cannot remove...