-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstack.c
69 lines (56 loc) · 905 Bytes
/
stack.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
#include <stdio.h>
#include <stdlib.h>
int top = -1, size;
void push(int Arr[]){
int a;
printf("Enter: ");
scanf("%d",&a);
if (top!=size-1)
{
Arr[++top] = a;
/* code */
}
}
int pop(int Arr[]){
int a;
a = Arr[top--];
return a;
}
void display_elements(int Arr[]){
for (int i = 0; i <= top; ++i)
{
printf(" %d ", Arr[i]);
/* code */
}
}
int main(int argc, char const *argv[])
{
int loop = 1;
printf("Size: \n");
scanf("%d",&size);
int *Arr = (int *)malloc(size* sizeof(int));
while(loop == 1)
{
int choice,a;
printf("Enter the choice 1-Push, 2-Pop, 3-Display, 4-Stop\n");
scanf("%d",&choice);
switch(choice){
case 1:
push(Arr);
break;
case 2:
if (top!= -1){
a = pop(Arr);
printf("%d \n",a );
}
break;
case 3:
display_elements(Arr);
break;
case 4:
loop = 0;
break;
}
}
return 0;
}