Untitled

 avatar
unknown
plain_text
15 days ago
839 B
3
Indexable
#include<stdio.h>
#define maxstk 5
//const int maxstk = 5;
int stack[maxstk];
int top = -1;
void display()
{
    if(top == -1)
    {
        printf("Stack is empty\n");
    }
    else
    {
        printf("Stack elements are");
        for(int i = top;i>=0;i--)
        {
            printf("%d\n",stack[i]);
        }
    }

}
void push()
{
    if(top == maxstk-1)
    {
        printf("Overflow\n");
        return ;
    }
    else
    {
        printf("Enter value for push");
        int x;
        scanf("%d",&x);
        top++;
        stack[top]=x;
    }
}
void pop()
{
   if(top == -1)
   {
       printf("Underflow\n");
       return;
   }
   else{
    printf("Popped element is %d\n",stack[top]);
    top--;
   }
}
int main()
{

    display();
    push();
    pop();

}

Editor is loading...
Leave a Comment