Name-Sawant Monal Sunil Class: SE (CSE) Roll No-15 Exp 1: Implementation of Stack Using Array
Name-Sawant Monal Sunil Class: SE (CSE) Roll No-15 Exp 1: Implementation of Stack Using Array
Name-Sawant Monal Sunil Class: SE (CSE) Roll No-15 Exp 1: Implementation of Stack Using Array
#include<stdio.h>
#include<conio.h>
#define MAX 5
void push();
void pop();
void display();
void exit();
int stack[MAX],top=-1;
void main()
{
int d;
printf("\n\t Stack Operation : ");
clrscr();
do
{
printf(" 1.PUSH 2.POP 3.DISPLAY 4.EXIT \nEnter your choice : ");
scanf("%d",&d);
switch(d)
{
case 1:push();break;
case 2:pop();break;
case 3:display();break;
case 4:exit();break;
}
}while(d!=4);
getch();
}
void push()
{
int val;
if(top==MAX-1)
{
printf("\n Stack is full : ");
}
else
{
printf("\n Enter new element : ");
scanf("%d",&val);
top=top+1;
stack[top]=val;
}
}
void pop()
{
if(top==-1)
{
printf("Stack is empty : ");
}
else
{
printf("\n deleted element=%d",stack[top]);
top=top-1;
}
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty : ");
}
else
{
for(i=top;i>=0;i--)
{
printf("%d\t",stack[i]);
}
}
}
OUTPUT :
Stack Operation :
1.PUSH 2.POP 3.DISPLAY 4.EXIT
Enter your choice : 1
Enter new element :55
Stack Operation :
1.PUSH 2.POP 3.DISPLAY 4.EXIT
Enter your choice :
88 77 66 55
Stack Operation :
1.PUSH 2.POP 3.DISPLAY 4.EXIT
Enter your choice : 2
deleted element=55
Stack Operation :
1.PUSH 2.POP 3.DISPLAY 4.EXIT
Enter your choice : 3
88 77 66