Professional Documents
Culture Documents
Practical 5 PDF
Practical 5 PDF
(Sem 3)
Practical No. 5
Program:
#include <stdio.h>
int stack[5];
int top=-1;
void push()
{
int num;
if( (top+1) == 5)
{
printf("\nStack Full\n");
}
else
{
printf("\nEnter a number...: ");
scanf("%d",&num);
top++;
stack[top]=num;
printf("\n%d added to Stack at %d position\n",num,top);
}
Data Structure Lab - S.Y. B. Tech. (Sem 3)
void pop()
{
int a;
if(top==-1)
{
printf("\nStack Empty\n");
}
else
{
a=stack[top];
printf("\n %d deleted from %d position : %d ",a,top);
top--;
}
}
void display()
{
int i;
if(top==-1)
{
printf("\nStack Empty\n");
}
else
{
printf("\n\n\nContents of the stack are : \n");
for(i=top;i>=0;i--)
{
printf("%d", stack[i]);
if(top == i)
printf("\t<--- TOP\n");
else
Data Structure Lab - S.Y. B. Tech. (Sem 3)
printf("\n");
}
}
}
void main()
{
int i,num,menuselect;
switch(menuselect)
{
case 1 : push(num);
break;
case 2 : pop();
break;
case 3 : display();
break;
} while(menuselect != 4);
}
Output: