Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MaxPilha 10
- struct TpPilhaM
- { int topo1, topo2;
- char Pilha[MaxPilha];
- };
- //operações associadas
- void Inicializa(TpPilhaM &PM);
- void Insere (TpPilhaM, &PM, int Id);
- char Retira (TpPilhaM, &PM, int Id);
- int Cheia (int topo1, int topo2);
- int Vazia (int topo1, int topo2);
- char ElementoTopo(TpPilhaM, PM, int Id);
- void Exibe (TpPilhaM, &PM, int Id);
- void Inicializa(TpPilha &PM)
- {
- PM.topo1=-1;
- PM.topo2=MaxPilha;
- }
- int Cheia(int topo1, int topo2)
- {
- return topo1+1==topo2;
- }
- void Insere(TpPilhaM &PM, char Elemen, int Id)
- {
- if(Id==1)
- PM.Pilha[++PM.topo1]=Elemem;
- else
- PM.Pilha[--PM.topo2]=Elemem;
- }
- void Vazia(int topo, int Id)
- {
- if(Id==1)
- return topo==1;
- else
- return topo==MaxPilha;
- }
- char ElementoTopo(TpPilaM PM, int Id)
- {
- if(id==1)
- return PM.Pilha[PM.topo1];
- else
- return PM.Pilha[PM.topo2];
- }
- char Retira (TpPilha &PM, int Id)
- {
- if(Id==1)
- return PM.Pilha[PM.Topo1];
- else
- return PM.Pilha[PM.Topo2];
- }
- void Exibe(TpPilha PM, int Id)
- {
- if(id==1)
- {
- while(!Vazia(PM.topo1, Id))
- {
- printf("\n%c", return (PM, Id));
- }
- }
- else
- while(!Vazia(PM.topo2, Id))
- {
- printf("\n%c", return (PM, Id));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement