2. Introduction to Stack
A Stack is a Linear Data Structure.
The Data Items in the stack are inserted and deleted from
one end. That is called Top of the stack.
Stack follows LIFO (Last In First Out) Mechanism.
Stacks are mostly used in system software. Like compilers and
Operating Systems, etc..
Insert values into stack is called push operation.
Reading Values from stack is called pop operation.
Patta Jagadeeswara Rao, MCA.
3. Introduction to Stack (Cont..)
The Stack starts with position of 0(zero) .
The Maximum Position of Stack is n-1.
When The position of Stack is zero. Then, the stack is
underflow.
When The position of Stack is grater than n-1. Then, the
stack is called overflow.
Once an item is popped from stack, it is no longer
available.
Patta Jagadeeswara Rao, MCA.
4. Stack Operations
There are Two operations in stack. Those are push
and pop.
The push operation is used to insert the values into
stack.
The pop operation is used to Retrieve the values from
the stack.
The best example for stack is the bunch of plates in
the kitchen.
Patta Jagadeeswara Rao, MCA.
5. Example for stack
# include <stdio.h>
# include <conio.h>
char jaggu[100];
int top = 0;
void push(void);
void pop(void);
void main()
{
Patta Jagadeeswara Rao, MCA.
6. Example for stack(cont..)
Int ch = 0;
while(1)
{
printf(“1. Add new item”);
printf(“2. Delete item”);
printf(“3. Quit”);
printf(“Enter Your Choice :”);
scanf(“%d”, &ch);
Patta Jagadeeswara Rao, MCA.