Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
1,917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  #define MaxiCola 100
  5.  
  6.  typedef struct {
  7.      char listCola[MaxiCola];
  8.      int fin;
  9.  } Cola;
  10.  void crearCola(Cola *C) {
  11.      C->fin = -1;
  12.  }
  13.  int colaFull( Cola C) {
  14.      if (C.fin == MaxiCola-1)
  15.          return 1;
  16.     else
  17.          return 0;
  18.  }
  19.  
  20.  void introducirCola(Cola *C, char elemento) {
  21.      if (colaFull(*C) == 1) {
  22.          printf("\nError: Desbordamiento de cola\n");
  23.          exit(1);
  24.      }
  25.      C->fin++;
  26.      C->listCola[C->fin] = elemento;
  27.  }
  28.  int colaPura(Cola C) {
  29.      if (C.fin == -1)
  30.         return 1;
  31.      else
  32.          return 0;
  33.  }
  34.  char eliminarCola(Cola *C) {
  35.      int i;
  36.     char aux;
  37.      if (colaPura(*C) == 1) {
  38.          printf("\nError: Cola Vacía\n");
  39.          exit(1);
  40.      }
  41.      aux = C->listCola[0];
  42.  
  43.      for(i=0; i < C->fin; i++) {
  44.          C->listCola[i] = C->listCola[i+1];
  45.      }
  46.           C->fin--;
  47.     return aux;
  48.  }
  49.  void aniquilarCola(Cola *C) {
  50.      C->fin = -1;
  51.  }
  52.  char proximaCola(Cola C) {
  53.      if(colaPura(C)==1) {
  54.          printf("Cola Vacía..");
  55.          exit(1);
  56.      }
  57.  
  58.      return C.listCola[0];
  59.  }
  60.  void exhibirCola(Cola C) {
  61.      int i;
  62.      if (colaPura(C) != 1) {
  63.          printf("\nMostramos los elementos de la Cola:\n");
  64.          for (i = 0; i <= C.fin; i++)
  65.          {
  66.              printf(" %c ", C.listCola[i]);
  67.          }
  68.          printf("\n\n");
  69.              } else  {
  70.         printf("\nNo hay elementos en la cola... cola vacía\n");
  71.          exit(1);
  72.      }                                                                  
  73. }  
  74. //FIN colaCabecera  
  75.      
  76.  
  77.  #define MaxiPila 100
  78.  
  79.   typedef struct {
  80.       char listPila[MaxiPila];
  81.       int Cima;
  82.   } Pila;
  83.   void crearPila(Pila *P) {
  84.       P->Cima = -1;
  85.   }
  86.   int pilaFull(Pila P){
  87.       if (P.Cima == MaxiPila-1)
  88.           return 1;
  89.       else
  90.           return 0;
  91.   }
  92.   void introducirPila(Pila *P, char elemento) {
  93.      if (pilaFull(*P) == 1) {
  94.         printf("\nError: Desbordamiento de pila\n");
  95.          exit(1);
  96.     }
  97.      P->Cima++;
  98.       P->listPila[P->Cima] = elemento;
  99.   }
  100.   int pilaPura(Pila P) {
  101.       if (P.Cima == -1)
  102.           return 1;
  103.       else
  104.           return 0;
  105.   }  
  106.   char eliminarPila(Pila *P) {
  107.       char Aux;
  108.       if(pilaPura(*P) == 1) {
  109.           printf("\nError: Intenta sacar elemento en pila vacía\n");
  110.          exit(1);
  111.       }
  112.       Aux = P->listPila[P->Cima];
  113.       P->Cima--;
  114.       return Aux;
  115.   }
  116.   void aniquilararPila(Pila *P) {
  117.       P->Cima = -1;
  118.   }
  119.   char cimaPila(Pila P) {
  120.       if(pilaPura(P)==1) {
  121.           printf("Pila Vacía..");
  122.           exit(1);
  123.       }
  124.  
  125.       return P.listPila[P.Cima];
  126.   }
  127.   void exhibirPila(Pila P) {
  128.      int i;
  129.       if (pilaPura(P) != 1) {
  130.           printf("\nMostramos los elementos de la Pila:\n");
  131.           for (i = 0; i <= P.Cima; i++)
  132.          {
  133.              printf("%c", P.listPila[i]);
  134.         }
  135.         printf("\n\n");
  136.     } else  {
  137.         printf("\nNo hay elementos en la pila... pila vacía\n");
  138.         exit(1);
  139.      }
  140.  }
  141.  
  142. // FIN pilaCabecera
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement