STACK
STACK
STACK
Data structure :
A Data Structure is a group of data that have different data types which can be accessed
as a unit .
A data structure has well-defined operations , behaviour and properties.
STACK
• Stack is a linear data structure
• Stack is a list of elements in which an element may be inserted or deleted only at
one end called the Top of the stack.
• It follows the principle Last In First Out (LIFO). LIFO means the element
inserted last would be the first to be deleted.
Operations on Stack
There are mainly two types of operations that can be done with stack
1. Push 2. Pop
Push : Insertion of an element on top of the stack is called Push.
Pop : Removal of an element from the top of the stack is called POP.
Note: Push and Pop operations are done from single end called TOP
Eg: Suppose a list of 5 items to be inserted in the stack .
2
Push 9 9
operation 4 4 4
56 56 56 56
24 24 24 24 24
Push 24 Push 56 Push 4 Push 9 Push 2 Stack
overflow
Maya Giby
PGT Computer Sc
2
Pop 9 9
operation 4 4 4
56 56 56 56
24 24 24 24 24
Pop Pop Pop Pop Pop Stack
underflow
Stack Overflow: It refers to a situation , when one tries to push an element in stack, that
is full .(Stacks are list implemented , since list can grow, overflow condition does not
arise until all memory is exhausted.
Stack Underflow : It refers to a situation when one tries to pop an item from an empty
stack .
Maya Giby
PGT Computer Sc