//To display stack operation
#include
#include
void main()
{
int top=0,val[15],li,ch,i;
clrscr();
printf("\nEnter the capacity of the stack\n");
scanf("%d",&li);
while(1)
{
printf("\n");
printf("\t\t\t Stack operation\n");
printf("\n\t 1. Push");
printf("\n\t 2. Pop");
printf("\n\t 3. Display stack");
printf("\n\t 4. Quit\n");
printf("\n\n\n Enter the choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
clrscr();
if(li==top)
{
printf("\n The stack is full");
}
else
{
printf("\nEnter the value:");
scanf("%d",&val[top]);
top++;
}
break;
case 2:
clrscr();
if(top==0)
{
printf("\nThe stack is empty\n");
}
else
{
top--;
printf("\n%d is removed from the stack ",val[top]);
val[top]=0;
}
break;
case 3:
clrscr();
if(top==0)
{
printf("There is No Element in the Stack");
}
else
printf("\n The elements of the stack are ");
for(i=top-1;i>=0;i--)
printf("\n %d",val[i]);
break;
default:
exit(0);
}
}
}
No comments:
Post a Comment