You are on page 1of 2

#include<process.

h>
#include<stdio.h>
#include<conio.h>
int stack[30];
int B[20], T[20], size[20];
void push(int x, int a)
{
if (T[x] == B[x + 1]) {
printf("\nStack over flow");
} else {
T[x]++;
stack[T[x]] = a;
}
}
void pop(int x)
{
int w;
if (T[x] == B[x]) {
printf("\nstack underflow");
} else {
w = stack[T[x]];
T[x]--;
printf("\npop element is %d", w);
}
}
void display(int x)
{
int i;
if (T[x] == B[x]) {
printf("\nstack underflow");
} else {
printf("\n");
for (i = T[x]; i > B[x]; i--) {
printf("%d ", stack[i]);
}
}
}
void main()
{
int i, n, x, c, u, s, m[30];
x = 0;
clrscr();
T[1] = 0;
B[1] = 0;
printf("\nEnter the total no stacks!!\n");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
printf("\nEnter the size of stack %d\n", i);
scanf("%d", &m[i]);
}
for (i = 1; i <= n; i++) {
x = x + m[i];
B[i + 1] = x;
T[i + 1] = x;
}
while (1) {
printf("\nEnter the choice\n1=push\n2=pop\n3=display\n4=exit\n!");
scanf("%d", &c);
switch (c) {
case 1:
printf("\nEnter the stack no: and item to be inserted!!\n");
scanf("%d%d", &x, &u);
push(x, u);
break;
case 2:
printf("\nEnter the stack no!!\n");
scanf("%d", &x);
pop(x);
break;
case 3:
printf("\nEnter the stack no!!\n");
scanf("%d", &x);
clrscr();
display(x);
getch();
break;
case 4:
exit(0);
break;
}
}
}

You might also like