Advertisement
rrcfs

Ed1

Mar 10th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define MaxPilha 10
  6. struct TpPilhaM
  7. {   int topo1, topo2;
  8.     char Pilha[MaxPilha];  
  9. };
  10. //operações associadas
  11. void Inicializa(TpPilhaM &PM);
  12. void Insere (TpPilhaM, &PM, int Id);
  13. char Retira (TpPilhaM, &PM, int Id);
  14. int Cheia (int topo1, int topo2);
  15. int Vazia (int topo1, int topo2);
  16. char ElementoTopo(TpPilhaM, PM, int Id);
  17. void Exibe (TpPilhaM, &PM, int Id);
  18.  
  19. void Inicializa(TpPilha &PM)
  20. {
  21.     PM.topo1=-1;
  22.     PM.topo2=MaxPilha; 
  23. }
  24. int Cheia(int topo1, int topo2)
  25. {
  26.     return topo1+1==topo2; 
  27. }
  28. void Insere(TpPilhaM &PM, char Elemen, int Id)
  29. {
  30.     if(Id==1)
  31.         PM.Pilha[++PM.topo1]=Elemem;
  32.     else
  33.         PM.Pilha[--PM.topo2]=Elemem;
  34. }
  35. void Vazia(int topo, int Id)
  36. {
  37.     if(Id==1)
  38.         return topo==1;
  39.     else
  40.     return topo==MaxPilha;
  41. }
  42.  
  43. char ElementoTopo(TpPilaM PM, int Id)
  44. {
  45.         if(id==1)
  46.         return PM.Pilha[PM.topo1];
  47.         else
  48.         return PM.Pilha[PM.topo2];
  49. }
  50. char Retira (TpPilha &PM, int Id)
  51. {
  52.     if(Id==1)
  53.     return PM.Pilha[PM.Topo1];
  54.     else
  55.     return PM.Pilha[PM.Topo2];
  56. }
  57. void Exibe(TpPilha PM, int Id)
  58. {
  59.         if(id==1)
  60.         {
  61.             while(!Vazia(PM.topo1, Id))
  62.             {
  63.                 printf("\n%c", return (PM, Id));
  64.             }  
  65.         }
  66.         else
  67.             while(!Vazia(PM.topo2, Id))
  68.             {
  69.                 printf("\n%c", return (PM, Id));
  70.             }
  71.        
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement