MIT-Curricular/DS/C/Lab/Week3/MulSta.c

49 lines
1017 B
C

#include <stdio.h>
#define NUM_STACKS 3
#define MAX 100
int top[NUM_STACKS];
int stack[NUM_STACKS][MAX];
void push(int stack_index, int value) {
if (top[stack_index] == MAX - 1) {
printf("Stack is full\n");
return;
}
stack[stack_index][++top[stack_index]] = value;
}
int pop(int stack_index) {
if (top[stack_index] == -1) {
printf("Stack is empty\n");
return -1;
}
return stack[stack_index][top[stack_index]--];
}
int main() {
for (int i = 0; i < NUM_STACKS; i++) {
top[i] = -1;
}
for (int i = 0; i < NUM_STACKS; i++) {
printf("Enter elements for Stack %d:\n", i + 1);
for (int j = 0; j < 5; j++) {
int value;
scanf("%d", &value);
push(i, value);
}
}
for (int i = 0; i < NUM_STACKS; i++) {
printf("Stack %d: ", i + 1);
for (int j = 0; j <= top[i]; j++) {
printf("%d ", stack[i][j]);
}
printf("\n");
}
return 0;
}