i want to implement multiple stacks using arrays..I am able to create ,insert and print them but not poping an element form any of the stack..This is what i have
Code:
#include<stdio.h>
#include<conio.h>
int top[5];
int bot[5];
void main()
{
int a[50]={0} ;
int length,num;
int ch;
int temp,x,st_no,st_no1;
int b,i,j,k;
clrscr();
printf("Enter the length of the total stack: ");
scanf("%d",&length);
printf("\nEnter the number of stacks: ");
scanf("%d",&num);
//divinding the arrays into stacks
b=(length)/(num);
top[0]=0;
bot[0]=0;
for(i=1;i<num;i++)
{
top[i]=top[i-1]+b;
bot[i]=bot[i-1]+b;
}
do
{
printf("\n1.PUSH 2.POP 3.PRINT 4.EXIT \n");
printf("Enter the choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter the stack number: ");
scanf("%d",&st_no);
if(top[st_no-1]==bot[st_no] || top[st_no-1]==length)
printf("\n\n\n!!THE %d STACK IS FULL\n",st_no);
else
{
printf("ENTER THE ELEMENT TO BE PUSHED");
scanf("%d",&x);
a[top[st_no-1]]=x;
top[st_no-1]=top[st_no-1]+1;
}
break;
//-------------------------------------------------------
case 2:
printf("\nENTER THE STACK NUMBER");
scanf("%d",&st_no1);
printf("\nThe stack you have choosen is %d",st_no1-1);
printf("-----%d-----",a[top[(st_no-1)]]);
if(top[st_no-1]==bot[st_no-1])
printf("\n!STACK EMPTY!\n");
else
{
printf("\nDELETED ELMENT IS: %d\n",a[top[st_no1-1]]);
top[st_no1-1]=top[st_no1-1]-1;
}
break;
//----------------------------------------------------------
case 3:
k=0;
for(i=0;i<num;i++)
{
printf("\nThe elements in stack %d are: ",i+1);
for(j=0;j<b;j++)
{
printf("%d->",a[i+j+k]);
}
k=k+b-1;
}
break;
}
}
while(ch<4);
getch();
}