#include<stdio.h>
#include<conio.h>
int
stack[100]={0};
int
ch,item,i,n,top=0;
main()
{
char
con;
clrscr();
printf("\n\t\tSTACK
OPERATION");
printf("\n\t\t~~~~~~~~~~~~~~~");
printf("\n\nEnter
the size of stack:");
scanf("%d",&n);
printf("\n\n");
do
{
printf("\n1.push");
printf("\n2.pop");
printf("\n3.display");
printf("\n4.exit");
printf("\nEnter
your choice:");
scanf("%d",&ch);
switch(ch)
{
case
1:
{
push();
break;
}
case
2:
{
pop();
break;
}
case
3:
{
display();
break;
}
}
}while(ch<=3);
getch();
}
push()
{
if(top==n+1)
printf("\n
stack is full");
else
{
printf("\nEnter
the item=");
scanf("%d",&stack[top]);
top++;
}
}
pop()
{
if(top==0)
printf("\nStack
is empty");
else
{
item=stack[top-1];
top--;
printf("\nDeleted
item is=%d",item);
}
}
display()
{
if(top==0)
printf("\nstack
is empty");
else
{
printf("\nThe
values are");
for(i=top;i>=1;i--)
printf("\n
%d",stack[i-1]);
}
}
No comments:
Post a Comment