#define MaxPilha 10
struct TpPilhaM2
{
int Base [MaxPilha], Topo[MaxPilha];
int Pilhas[MaxPilha];
};
void Inicializa (TpPilhaM2 &PM, int QtdePilhas)
{
int qtde, i;
qtde = MaxPilha / QtdePilhas;
for (i = 0; i <= QtdePilhas; i++)
{
PM.Base[i] = i * qtde;
PM.Topo[i] = i * qtde - 1;
}
}
int Vazia (TpPilhaM2 PM, int NrP)
{
return PM.Base[NrP - 1] > PM.Topo[NrP - 1];
}
int Cheia (TpPilhaM2 PM, int NrP)
{
return PM.Topo[NrP - 1] + 1 == PM.Base[NrP];
}
void Insere (TpPilhaM2 &PM, int Elem, int NrP)
{
PM.Pilhas[PM.Topo[NrP - 1]++] = Elem;
}
int Retira (TpPilhaM2 &PM, int NrP)
{
return PM.Pilhas[PM.Topo[NrP - 1]--];
}
int RetornaElemTopo (TpPilhaM2 PM, int NrP)
{
return PM.Pilhas[PM.Topo[NrP - 1]];
}
void Exibe (TpPilhaM2 PM, int NrP)
{
while(!Vazia(PM, NrP))
printf("%d",Retira(PM, NrP));
}