//Program for Stack
#include<stdio.h>
#include<conio.h>
#define N 10
void push();
void pop();
void display();
void peak();
int s[N]; // s= Stack & N= Capacity.
int top=-1;
void main()
{
int c;
clrscr();
do
{
printf(" \nplease enter a choice
\n1.Push\n2.Pop\n3.Display\n4.Peak\n5.exit");
scanf("%d",&c);
switch(c)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: peak();
break;
}
}while(c<=4);
if(c==5)
printf("\n Thankyou ");
getch();
}
void push()
{
int ele;
if(top==N-1)
printf(" the stack is full ");
else
{
printf(" enter the element ");
scanf("%d",&ele);
top++;
s[top]=ele;
printf(" the element entred is %d",s[top]);
}
}
void pop()
{
if(top==-1)
{
printf(" the stack is empty ");
}
else
{
printf(" element deleted is %d",s[top]);
top--;
}
}
void display()
{
int i;
if(top==-1)
printf(" the stack is empty ");
else
{
printf(" the elements are ");
for(i=0;i<=top;i++)
{
printf(" %d ",s[i]);
}
}
}
void peak()
{
printf(" element at peak is %d ",s[top]);
}
OUTPUT:-
1>Push:-
2>Pop:-
3>Display:-
4>Peak:-