/*
Program to implement STACKS as an array clearly depicting the ‘Push’ and ‘Pop’ operations
*/
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
void main()
{
clrscr();
int top=0,choice,n,item,i,A[25];
printf(“nnn Enter the choice::nnn 1==>’Push the element in stack’nn”);
printf(” 2==>’Pop the element off stack’nn 3==> Exitnnn Your Choice::”);
scanf(“%d”,&choice);
printf(“n Enter the maximum size of STACK::”);
scanf(“%d”,&n);
while((choice==1)||(choice==2)||(choice==3))
{
switch(choice)
{
case 1: //Push the elements in Stack .
{
printf(“n Enter the element to be pushed::”);
scanf(“%d”,&item);
if(top==n)
{
printf(“nn STACK OVERFLOW!!”);
break;
}
else
{
top=top+1;
A[top]=item;
}
break;
}
case 2: //Pop the elements out of Stack .
{
if(top==0)
{
printf(“nn STACK UNDERFLOW!!”);
break;
}
else
top=top-1;
break;
}
case 3: //Exit the operations.
{
if(top>0)
{
printf(“n The elements in stacks are::”);
for(i=1;i<=top;i++)
printf(“%d “,A[i]);
delay(4000);
exit(0);
}
break;
}
}
printf(“nnn Enter your choice::”);
scanf(“%d”,&choice);
}
}
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.