To begin, let's talk about a stack. It is an easy-to-understand data structure and can be represented using the example of a pile of many plates, each placed on top of the other. You can only add a new plate to the top of the pile, and you can only get a plate from the top of the pile. You cannot remove the seventh plate without taking the previous six from the top, and you cannot add a plate to the middle of the pile.
The stack operates in exactly the same way! It allows you to 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 stands for Last-In First-Out. According to our example of the pile of plates, the last added plate (last-in) will be removed from the pile first (first-out).
The diagram of a stack with push and pop operations is shown as follows:
It seems to be very easy, doesn't it? It really is, and you can benefit from the features of stacks...