Stack Data Structure
Stack Data Structure
A stack is a data structure that holds a list of elements. A stack works based on the
LIFO principle i.e., Last In, First out, meaning that the most recently added element
is the first one to remove.
A stack has two main operations that occur only at the top of the stack: push and
pop. The push operation places an element at the top of stack whereas the pop
operation removes an element from the top of the stack.
The name stack comes from the analogy to a set of physical items e.g., DVD disc,
books, stacked on top each other.
Operations on Stack
www.vectorindia.org 1
Stack Data Structure
Initially, the stack has 5 elements. The pop() method removes the
element at the end of the array i.e., at the top of the stack one at a
time. After five operations, the stack is empty
www.vectorindia.org 2
Stack Data Structure
Applications of Stack
Expression Evaluation
Expression Conversion
Syntax Parsing
www.vectorindia.org 3
Stack Data Structure
Backtracking
Parenthesis Checking
String Reversal
Function Call
Note :
Reference Books : Taken contents and diagrams from various websites.
www.vectorindia.org 4