forked from satyamvats5/DataStructure_Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.c
216 lines (98 loc) · 1.96 KB
/
5.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* Write a menu driven program (in C) for complete implementation of stack using array with push, pop and display operation. */
#include<stdio.h>
int top = -1; //the global variable
int PUSH(int MAX, int STACK[]) // function for push opertion in a stack
{
int value;
if(top == MAX-1)
printf("\nSTACK OVERFLOW\n\n");
else
{
printf("\nEnter a value : ");
scanf("%d", &value);
top++;
STACK[top] = value;
}
return 0;
}
int POP(int MAX, int STACK[]) // function for pop operation in the stack
{
int value;
if(top == -1)
printf("\n\nTHE STACK IS EMPTY\n\n");
else
{
value = STACK[top];
top--;
printf("\n%d is deleted from the STACK. \n\n", value);
}
return 0;
}
int DISPLAY(int MAX, int STACK[]) // to display the elements in stack
{
int i;
if(top == -1)
printf("\nTHE STACK IS EMPTY\n\n");
else
{
printf("The STACK is : \n");
for(i=top; i>= 0; i--)
printf("\n\t%d", STACK[i]);
printf("\n");
}
return 0;
}
int MENU(int MAX, int STACK[]) // to implement the menu
{
int option;
printf("\n--------------------");
printf("\n*****MAIN MENU*****");
printf("\nEnter 1. To PUSH");
printf("\nEnter 2. To POP");
printf("\nEnter 3. To DISPLAY");
printf("\nEnter 4. To EXIT");
printf("\n____________________\n");
printf("\nEnter your choice : ");
scanf("%d", &option);
printf("\n--------------------\n\n");
switch(option)
{
case 1:
{
PUSH(MAX, STACK);
MENU(MAX, STACK);
}
break;
case 2:
{
POP(MAX, STACK);
MENU(MAX, STACK);
}
break;
case 3:
{
DISPLAY(MAX, STACK);
MENU(MAX, STACK);
}
break;
case 4:
return 0;
break;
default:
{
printf("\nSorry ...!\nWrong entry...\nPlease enter the correct one.\n\n");
MENU(MAX, STACK);
}
break;
}
return 0;
}
int main()
{
int MAX;
printf("\nEnter the size of stack : ");
scanf("%d", &MAX);
int STACK[MAX];
MENU(MAX, STACK);
return 0;
}