Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
14
Indexable
#include<stdio.h>
#define max 50

int arr[max];
int top=-1;
void push(int);
void pop();
void peep();

main()
{
    int d,ch;

    while(1)
    {
        printf("\n1:-push\n2:-pop\n3:-peep\n");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:
        printf("ENTER ELEMENT FOR PUSH");
        scanf("%d",&d);
        push(d);
        break;
    case 2:
        pop();
        break;
    case 3:
        peep();
        break;

    }
    }

}
void push(int d)
{
    if(top>=max)
        printf("\n\n\t\t****STACK OVERFLOWED****");
    else
    {
         top=top+1;
         arr[top]=d;
    }
}
void pop()
{
    if(top==-1)
        printf("\n\n\t\t****STACK UNDERFLOWED****");
    else
    {
        printf("POPED ELEMENT IS -> %d",arr[top]);
        top=top-1;
    }
}
void peep()
{
    printf("\nENTERED STACK IS :- ");
    printf("\n%d <- TOP",arr[top]);
    for(int i=top-1;i>=0;i--)
    {
        printf("\n%d",arr[i]);
    }

}

Editor is loading...
Leave a Comment