Stack using Array
Stack using Array
h>
#define MAX 5
int a[MAX];
int top;
} stack;
int main() {
stack s;
int n, ch, num_elements; // `n` for the element and `ch` for choice
printf("Enter number of elements to initialize the stack (max %d): ", MAX);
do {
switch (ch) {
if (!isfull(&s)) {
} else {
break;
if (!isempty(&s)) {
} else {
break;
case 3: // Display the stack
display(&s);
break;
break;
default:
return 0;
}
int isempty(stack *p) {
if (isempty(p)) {
} else {
OUTPUT:
/tmp/b2ktdLsJ17.o
Enter 3 elements:
463
1. Push
2. Pop
3. Print
4. Quit
Element 5 pushed.
1. Push
2. Pop
3. Print
4. Quit
a[3] = 5
a[2] = 3
a[1] = 6
a[0] = 4
1. Push
2. Pop
3. Print
4. Quit
Element popped: 5
1. Push
2. Pop
3. Print
4. Quit
1. Push
2. Pop
3. Print
4. Quit
Enter your choice: 4