-
Notifications
You must be signed in to change notification settings - Fork 1
/
TADPilha.h
59 lines (48 loc) · 950 Bytes
/
TADPilha.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define MAXPILHA 30
struct TpPilhaM2
{
int BASE[MAXPILHA], TOPO[MAXPILHA], QTP,cont[10];
char Pilha[MAXPILHA];
};
//Operações Associadas
void Inicializar(TpPilhaM2 &PM, int QTP)
{
int QtdeElem = MAXPILHA / QTP;
PM.cont[0]=0;
PM.QTP = QTP;
PM.BASE[0] = 0;
PM.TOPO[0] = -1;
for(int i = 1 ; i < QTP ; i++)
{
PM.BASE[i] = PM.BASE[i - 1] + QtdeElem;
PM.TOPO[i] = PM.TOPO[i - 1] + QtdeElem;
PM.cont[i]=0;
}
}
char Vazia(TpPilhaM2 PM, int NP)
{
return PM.TOPO[NP] == PM.BASE[NP] - 1;
}
char Cheia(TpPilhaM2 PM, int NP)
{
return PM.TOPO[NP] == PM.BASE[NP] + PM.QTP - 1;
}
void Inserir(TpPilhaM2 &PM, int NP, char Elem)
{
PM.cont[NP]++;
PM.Pilha[++PM.TOPO[NP]] = Elem;
}
char Retirar(TpPilhaM2 &PM, int NP)
{
PM.cont[NP]--;
return PM.Pilha[PM.TOPO[NP]--];
}
char ElemTopo(TpPilhaM2 PM, int NP)
{
return PM.Pilha[PM.TOPO[NP]];
}
void Exibe(TpPilhaM2 PM, int NP)
{
while(!Vazia(PM,NP))
printf("%c\n",Retirar(PM,NP));
}