Name-Sawant Monal Sunil Class: SE (CSE) Roll No-15 Exp 1: Implementation of Stack Using Array

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

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

1.PUSH 2.POP 3.DISPLAY 4.EXIT


Enter your choice : 1
Enter new element :66

1.PUSH 2.POP 3.DISPLAY 4.EXIT


Enter your choice : 1
Enter new element :77

1.PUSH 2.POP 3.DISPLAY 4.EXIT


Enter your choice : 1
Enter new element :88

1.PUSH 2.POP 3.DISPLAY 4.EXIT


Enter your choice : 1
Enter new element :99

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy