-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackByArrays.c
More file actions
87 lines (84 loc) · 1.56 KB
/
stackByArrays.c
File metadata and controls
87 lines (84 loc) · 1.56 KB
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
#include <stdio.h>
#include <stdlib.h>
int arr[10];
int INDEX = -1;
int push(int item)
{
if (INDEX == 9)
{
return -1;
}
else
{
INDEX++;
arr[INDEX] = item;
return 0;
}
}
int pop()
{
if (INDEX == -1)
{
return -1;
}
else
{
INDEX--;
return 0;
}
}
int main(void)
{
while (1)
{
int choice, item;
printf("Choice No:\n");
printf("1. Push\n2. Pop\n3. View Stack\n4. Exit\n");
printf("Enter Choice No: ");
scanf(" %d", &choice);
switch (choice)
{
case 1:
printf("Enter Value: ");
scanf(" %d", &item);
if (push(item) == 0)
{
printf("Successfully Pushed to Stack!!");
}
else
{
printf("Stack is Full!!");
}
break;
case 2:
if (pop() == 0)
{
printf("Successfully Popped from Stack!!");
}
else
{
printf("Stack is Empty!!");
}
break;
case 3:
if (INDEX == -1)
{
printf("Stack is Empty!!");
}
else
{
int i;
for (i = 0; i <= INDEX; i++)
{
printf("%d ", arr[i]);
}
}
break;
default:
exit(0);
break;
}
printf("\n");
}
return 0;
}