Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
0
Indexable
Never
#include<stdio.h>
#include<stdlib.h>
#define size 10
int stack[size];
int top=-1;
void push(int x)
{
 if(top==size-1)
 printf("\n stack overflow occur,insertion not possible");
  else
  {
    top=top+1;
    stack[top]=x;
  printf("\ninsertion successfull");
  }
 }
  void pop()
  {
   if(top==-1)
   printf("\n stack underflow,deletion not possible");
   else
    {
     int
     temp=stack[top];
     top--;
   printf("\n deletion element=%d",temp);
   }
  }
void display()
{
 int i;
 printf("\n the elements in the stack are:");
 for(i=top;i>=0;i--)
 printf("%d",stack[i]);
 }
void main()
{
 int ch,value;
 while(1)
 {
  printf("\n menu---\n");
  printf("\n1.insert\n2.delete\n3.display\n4.exit");
  printf("\nenter the choice:");
  scanf("%d",&ch);
  switch(ch)
  {
   case 1:
   printf("\n value to be inserted is:");
   scanf("%d",&value);
   push(value);
   break;
   case 2:pop();
   break;
   case 3:display();
   break;
   case 4:exit(0);
   break;
   default:printf("\nwrong choice!!");
   }
  }
}