Stack Data Structure
The third and final list-typed data structure we will go over is the stack. A stack follows the Last In First Out (LIFO) structure, meaning that the most recent node to be added to the stack will be the first one removed. This is slightly different from the queue data structure which you can read about here. To better understand the stack data structure, visualize plates stacked on top of each other. The last plate that was placed on the stack is the first to be taken. Software applications of a stack are: undoing actions, going back an internet page, and evaluating expressions.
Below is a basic implementation of a stack in C++. We implement it using a doubly linked list and with three main functions:
Push - Add a node to the end of the stack
Pull - remove and return the node at the end of the stack
Peek - return the value of the end node but don't remove it