#include
#define max 5
int top=-1;
int a[max];
void push();
void pop();
void peep();
int isempty();
int isfull();
main()
{ int n,p,q;
do
{
printf("\n\n\n\nenter your choice number:\n
1.push an element\n
2.pop an element\n
3.peep an element\n
4.check, is stack empty?\n
5.check, is stack full?\n
6.end the program\n");
scanf("%d",&n);
switch(n)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peep();
break;
case 4:
p=isempty();
if(p==1)
printf("the stack is empty\n");
else
printf("the stack is not empty\n");
break;
case 5:
q=isfull();
if(q==1)
printf("the stack is full\n");
else
printf("the stack is not full\n");
break;
case 6:
printf("\t---------------THANKS FOR USING-----------------\n\n");
break;
default:
printf("please enter the number 1 to 5 only :\n");
scanf("%d",&n);
}
}while(n<6);
}
void push()
{
int s,x;
s=isfull();
if(s==1)
{
printf("\nstack is overflow\n");
}
else
{
printf("enter the element\n");
scanf("%d",&x);
a[++top]=x;
}
return;
}
int isfull()
{
if(top==max-1)
return(1);
else
return(0);
}
void pop()
{
int s,x;
s=isempty();
if(s==1)
{
printf("the stack is underflow\n");
}
else
{
x=a[top--];
printf("the poped element is %d\n",x);
}
return;
}
int isempty()
{
if(top==-1)
return(1);
else
return(0);
}
void peep()
{
int i;
printf("the element in the stack are :\n");
for(i=top;i>=0;i--)
{
printf("\t\t\t\t%d\n",a[i]);
}
return;
}
No comments:
Post a Comment