Repository navigation
Expand file tree
/
Copy pathstackArray.c
More file actions
90 lines (83 loc) · 1.38 KB
/
Copy pathstackArray.c
File metadata and controls
90 lines (83 loc) · 1.38 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
88
89
90
/** implementation of stack data structure using array in c */
#include <stdio.h>
int Stack[100];
int StackSize = 0;
void push()
{
if (StackSize == 100)
{
printf("Stack is full");
}
else
{
int val;
printf("Enter the value to push: ");
scanf("%d", &val);
Stack[StackSize] = val;
StackSize++;
}
}
void pop()
{
if (StackSize == 0)
{
printf("Stack is empty");
}
else
{
StackSize--;
}
}
void isEmpty()
{
if (StackSize == 0)
{
printf("Stack is empty");
}
else
{
printf("Stack is not empty");
}
}
void isFull()
{
if (StackSize == 100)
{
printf("Stack is full");
}
else
{
printf("Stack is not full");
}
}
void main()
{
int choice;
printf("1. Push\n2. Pop\n3. isEmpty\n4. isFull\n5. Exit\n");
do
{
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
isEmpty();
break;
case 4:
isFull();
break;
case 5:
printf("Exiting...");
break;
default:
printf("Invalid choice");
break;
}
} while (choice != 5);
}