-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackarray.c
92 lines (89 loc) · 1.72 KB
/
stackarray.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<stdio.h>
#include<stdlib.h>
//#include<conio.h>
#define max 50
int top=-1;
int st[max];
void Push(int);
void Pop();
void display();
int main()
{
int ch=0,n;
while(ch!=4)
{
printf("\nWhat do you want to do?\n");
printf("\n1.Push an element");
printf("\n2.Pop an element");
printf("\n3.Display the stack");
printf("\n4.Exit");
printf("\nEnter your choice(1/2/3/4):");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("\nEnter the element:");
scanf("%d",&n);
Push(n);
/*printf("\nPress any key to continue:");
getch();*/
break;
}
case 2:
{
Pop();
/*printf("\nPress any key to continue:");
getch();*/
break;
}
case 3:
{
display();
/*printf("\nPress any key to continue:");
getch();*/
break;
}
case 4:
break;
default:
{
printf("\nPlease check and enter");
break;
}
}
}
return 0;
}
void Push(int ele)
{
if(top==max)
printf("\nOverflow!!");
else
{
top++;
st[top]=ele;
}
}
void Pop()
{
int e;
if(top==-1)
printf("\nUnderflow!!");
else
{
e=st[top];
top--;
printf("\nThe deleted element:%d",e);
}
}
void display()
{
int i=top;
printf("\n");
while(i>=0)
{
printf("%d-",st[i]);
i--;
}
}