stack push pop exit

#include<stdio.h>
#include<conio.h>
struct stack
{
	int top;
   int item[10];
};
int main ()
{
	int n,choise=0;
   struct stack s;
   struct stack *ps;
   clrscr();
   s.top=-1;
   while(choise!=4)
   {
   	printf("\n1. Push\n2. Pop\n3. Stack Show\n4. END\n\nEnter your choise: ");
      scanf("%d",&choise);
      if(choise==1)
      {
      	if(stack_full(&s))
         {
         	printf("\nStack is full!\n");
         }
         else
         {
         	printf("Enter an integer to Push: ");
            scanf("%d",&n);
            push(&s,n);
         }
      }
      if(choise==2)
      {
      	if(stack_empty(&s))
         {
         	printf("\nStack is Empty!\n");
         }
         else
         	pop(&s);
      }
      if(choise==3)
      {
      	if(stack_empty(&s))
         {
         	printf("\nStack is Empty!\n");
         }
         else
         	show_stack(&s);
      }
   }
}

push(ps,x)
struct stack *ps;
int x;
{
	++ps->top;
   ps->item[ps->top]=x;
}

pop(ps)
struct stack *ps;
{
	ps->top--;
}

show_stack(ps)
struct stack *ps;
{
	int i;
   printf("\nStack contains: ");
   for(i=0;i<=ps->top;i++)
   	printf("%d ",ps->item[i]);
}

stack_full(ps)
struct stack *ps;
{
	if(ps->top==9)
   	return 1;
   else
   	return 0;
}

stack_empty(ps)
struct stack *ps;
{
	if(ps->top==-1)
   	return 1;
   else
   	return 0;
}

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *