-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathpush and pop.c
78 lines (70 loc) · 1.52 KB
/
push and pop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<stdio.h>
#define size 5
int top=-1;
int stack[size];
void push();
void pop();
void display();
void main()
{
int ch;
while(ch!=4)
{
printf("\n1.PUSH AN ELEMENT\n2.POP AN ELEMENT\n3.DISPLAY STACK\n4.EXIT\n");
printf("STACK MENU : ");
scanf("%d",&ch);
switch (ch)
{
case 1 :push();
break;
case 2 :pop();
break;
case 3 :display();
break;
case 4 :exit(0);
default:printf("\nINVALID ENTRY...!!!!");
}
}
}
void push()
{
int element;
if(top==(size-1))
{
printf("\nSTACK OVERFLOW\n");
}
else
{
top++;
printf("\nENTER THE ELEMENT TO BE PUSHED : ");
scanf("%d",&element);
stack[top]=element;
}
}
void pop()
{
if(top==-1)
{
printf("\nSTACK EMPTY");
}
else
{
printf("\nDELETED ELEMENT IS : %d" ,stack[top]);
top--;
}
}
void display()
{
if(top==-1)
{
printf("\nSTACK IS EMPTY :(");
}
else
{
printf("\nELEMENTS IN THE STACK : \n");
for(int i=top;i>-1;i--)
{
printf("%d \n",stack[i]);
}
}
}