#include<stdio.h>
#define MAX 10
int top1 = -1;
int top2 = MAX;
int a[MAX];
void push(int e,int s);
int pop(int s);
int main()
{
int n ,e,s;
do
{
printf("\n enter choice \n 1 for push \n 2 for pop \n 3 for exit \n ");
scanf("%d",&n);
switch(n)
{
case 1:
{
printf("\n choose the stack 1 or 2 \n");
scanf("%d",&s);
printf("\n enter the element \n");
scanf("%d",&e);
push(e,s);
break;
}
case 2:
{
int e;
printf("\n enter your stack preffrence 1 or 2 ");
scanf("%d",&s);
e = pop(s);
if(e != -1)
{
printf("\n the pop element = %d \n",e);
}
break;
}
default:
printf("\n enter the correct choice \n");
}
}while(n!=3);
}
int pop(int s)
{
int temp;
if(s==1)
{
if(top1==-1)
{
printf("stack 1 is empty \n");
return -1;
}
else
{
temp = a[top1];
top1--;
return temp;
}
}
else
{
if(top1==MAX)
{
printf("stack 2 is empty \n");
return -1;
}
else
{
temp = a[top2];
top2++;
return temp;
}
}
}
void push(int e,int s)
{
if(top1==top2)
{
printf("\n the queue is full");
return;
}
else
{
if(s==1)
{
top1++;
a[top1]=e;
printf("\n element inserted in stack 1 \n");
}
else
{
top2--;
a[top2]==e;
printf("\n element inserted into stack 2 \n ");
}
}
}
#define MAX 10
int top1 = -1;
int top2 = MAX;
int a[MAX];
void push(int e,int s);
int pop(int s);
int main()
{
int n ,e,s;
do
{
printf("\n enter choice \n 1 for push \n 2 for pop \n 3 for exit \n ");
scanf("%d",&n);
switch(n)
{
case 1:
{
printf("\n choose the stack 1 or 2 \n");
scanf("%d",&s);
printf("\n enter the element \n");
scanf("%d",&e);
push(e,s);
break;
}
case 2:
{
int e;
printf("\n enter your stack preffrence 1 or 2 ");
scanf("%d",&s);
e = pop(s);
if(e != -1)
{
printf("\n the pop element = %d \n",e);
}
break;
}
default:
printf("\n enter the correct choice \n");
}
}while(n!=3);
}
int pop(int s)
{
int temp;
if(s==1)
{
if(top1==-1)
{
printf("stack 1 is empty \n");
return -1;
}
else
{
temp = a[top1];
top1--;
return temp;
}
}
else
{
if(top1==MAX)
{
printf("stack 2 is empty \n");
return -1;
}
else
{
temp = a[top2];
top2++;
return temp;
}
}
}
void push(int e,int s)
{
if(top1==top2)
{
printf("\n the queue is full");
return;
}
else
{
if(s==1)
{
top1++;
a[top1]=e;
printf("\n element inserted in stack 1 \n");
}
else
{
top2--;
a[top2]==e;
printf("\n element inserted into stack 2 \n ");
}
}
}
