#include<stdio.h>
    #define SIZE 10
         struct stack{
int a[SIZE];
int top;
 };
 struct stack s;
 s .top=-1;
 void push(int value);

   void pop();
       void display();
     void peakelement();
      int main()
 {
int choice,value;
while(1)
{
    printf("\n1.push  2. pop   3.display   4. peakelement 5. exit");
    printf("enter your choice");
    scanf("%d",&choice);
    if(choice==1)
      {
          printf("enter value to be pushed");
          scanf("%d",&value);
          push(value);
      }
    else if(choice==2)
    {
        pop();
    }
    else if(choice==3)
    {
        display();
    }
    else if(choice==4)
    {
        peakelement();
    }
    else if(choice==5)
    {
        break;
    }
}
return 0;
}
void push(int value)
{
if(s.top==size-1)
  printf("stack overflow");
else
{
    s.top=s.top+1;
    s.a[s.top]=value;
}
}
void pop()
{
if(s.top==-1)
  printf("stack underflow");
else
{
    printf("%d is deleted",s.a[s.top]);
    s.top=s.top-1;
}
}
   void display()
  {
int i;
printf("values in stack are");
for(i=s.top;i>=0;i--)
{
    printf("%d  ",s.a[i]);
}
 }
   void peakelement()
  {
printf("peak element is %d",s.a[s.top]);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.