//fms
//multiple stack
#include<stdio.h>
#include<conio.h>
int st[20],size[20],lb,ub,t[10],j,d,n;
void setst(int i)
{
if(i==1)
{
lb=0;
ub=(n-1);
//printf("\n%d %d",lb,ub);
}
else
{
lb=(i-1)*n;
ub=(i)*n-1;
//printf("\n%d %d",lb,ub);
}
}
void initialise()
{
int p;
for(p=0;p<10;p++)
{
setst(p+1);
t[p]=lb;
}
}
void push(int itm,int i)
{
int top;
setst(i);
top=t[i-1];
if(top>ub)
{
printf("\nStack %d full!",i);
return;
}
else
{
st[top]=itm;
top++;
t[i-1]=top;
}
}
void pop(int i)
{
int top,itm;
setst(i);
top=t[i-1];;
if(top<lb)
printf("\nStack %d empty!",i);
else
{
itm=st[top];
st[top]=0;
top--;
t[i-1]=top;
}
}
void disp(int i)
{
int top,k;
setst(i);
top=t[i-1];
for(k=top-1;k>=lb;k--)
{
printf("\n%d\n",st[k]);
}
}
void main()
{
int i,index,itm,ch,w;
clrscr();
printf("\nEnter size of array:");
scanf("%d",&j);
printf("\nEnter how many stack?");
scanf("%d",&d);
n=(j/d);
initialise();
do
{
printf("\nEnter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:printf("\nEnter item:");
scanf("%d",&itm);
printf("\nEnter stack number:");
scanf("%d",&i);
setst(i);
push(itm,i);
break;
case 2:printf("\nEnter stack number:");
scanf("%d",&i);
pop(i);
break;
case 3:printf("\nIndex of stack:");
scanf("%d",&i);
disp(i);
break;
case 4:dispall(d);
break;
case 5:exit(0);
}
}while(1);
getch();
}
dispall(int d)
{
int k,index,i;
for(index=1;index<=d;index++)
{
printf("Stack number is %d\n",index);
setst(index);
for(k=ub;k>=lb;k--)
{
printf("\n%d\n",st[k]);
}
}
}
No comments:
Post a Comment