Thursday, 18 July 2013

Program in C to perform PUSH and POP on Stack

#include<stdio.h>
#include<conio.h>
void main()
{
int S[10],MAXSTK,TOP=0,item,n,i,D;
clrscr();
do
{
printf(“Enter the size\n”);
scanf(“%d”,&n);
printf(“Enter the choice \n1-Push \n2-Pop\n3-Display”);
scanf(“%d”,&n);
switch(n)
{
case 1:
{
if(TOP==MAXSTK)
{
printf(“Overflow”);
break;
}
else
{
printf(“Enter the item you want to insert ”);
scanf(“%d”,&item);
TOP=TOP+1;
S[TOP]=item;
break;
}
}
case 2:
{
if(TOP==0)
{
printf(“Underflow”);
}
else
{
item=S[TOP];
TOP=TOP-1;
printf(“Delete the item”,item);
bbreak;
}
}
case 3:
{
for(i=TOP;i>0;i--)
{
scanf(“%d”,S[i]);
break;
}
}
printf(“Enter 4 to continue\n”);
scanf(“%d”,&D);
}
while(D==4);
getch();

}

No comments:

Post a Comment