unit-2
unit-2
STACK
Stack is a Linear Data Structure that follows Last In First Out (LIFO) principle.
Insertion and deletion can be done at only one end of the stack called TOP of the stack.
Example: - Pile of coins, stack of trays
TOP pointer
It will always point to the last element inserted in the stack.
For empty stack, top will be pointing to -1. (TOP = -1)
Implementation of Stack
Stack can be implemented in 2 ways.
1. Static Implementation (Array implementation of Stack)
2. Dynamic Implementation (Linked List Implementation of Stack)
Applications of Stack
The following are some of the applications of stack:
1. Evaluating the arithmetic expressions
Conversion of Infix to Postfix Expression
Evaluating the Postfix Expression
2. Balancing the Symbols
3. Function Call
4. Tower of Hanoi
5. 8 Queen Problem
INFIX:
The arithmetic operator appears between the two operands to which it is being applied.
A/B+C
POSTFIX:
The arithmetic operator appears directly after the two operands to which it applies. Also called
reverse polish notation.
PREFIX:
The arithmetic operator is placed before the two operands to which it applies. Also called polish
notation.
Implementation of Queue
Queue can be implemented in two ways.
1. Implementation using Array (Static Queue)
2. Implementation using Linked List (Dynamic Queue)
Initial Configuration of Queue:
FULL QUEUE