Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

#include<stdio.

h>

#include<conio.h>

#include<stdlib.h>

#define N 5

int stack[N];

int top=-1;

void push(int x);

void pop();

void display();

void peek();

int main()

int value,choice;

while(1)

printf("\n\n***********MENU**********\n\n");

printf("\n1.PUSH\n2.POP\n3.DISPLAY\n4.PEEK\n");

printf("Enter your choice");

scanf("%d",&choice);

switch(choice)

case 1:

printf("Enter the value to be inserted:");

scanf("%d",&value);

push(value);

break;

case 2:

pop();
break;

case 3:

display();

break;

case 4:

peek();

break;

void push(int value)

if(top==N-1)

printf("Stack is overflowed");

else

top++;

stack[top]=value;

printf("\nInsertion ");

void pop()

{
if(top==-1)

printf("Stack is underflowed");

else

printf("\nDeleted : %d",stack[top]);

top--;

void display()

int i;

if(top==-1)

printf("Stack is empty");

else

printf("\nStack elements are:\n");

for(i=top;i>=0;i--)

printf("%d",stack[i]);

void peek()

if(top==-1)

{
printf("Stack is empty");

else

printf("%d",stack[top]);

You might also like