Advertisement
luciana1237

Untitled

Jul 21st, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. #define MAX_PISTAS 3
  6.  
  7. typedef struct No {
  8.     int pista[MAX_PISTAS],size;
  9.     struct No *prox;
  10. }fila;
  11.  
  12. fila *fila_cria(void)
  13. {
  14.     fila *f = (fila *) malloc(sizeof(fila));
  15.    
  16.     if (f != NULL)
  17.         f->prox = NULL;
  18.    
  19.     return f;
  20. }
  21.  
  22. bool isEmpty(fila *f)
  23. {
  24.     return(f->prox == NULL);
  25. }
  26.  
  27. bool enfileirar(fila *f,int p,int v)
  28. {
  29.     fila *no = (fila *) malloc(sizeof(fila));
  30.    
  31.     if (no == NULL)
  32.         fprintf(stderr,"erro");
  33.    
  34.     no->pista[ p ] = v;
  35.     no->prox = NULL;
  36.    
  37.     if (isEmpty(f))
  38.         no->prox = no;
  39.     else
  40.         no->prox = no;
  41.     no->prox =no;
  42.     f->size++;
  43.     return true;
  44. }
  45.  
  46. void imprime(fila *f)
  47. {
  48.     printf("[ %d ] ",f->pista[0 ]);
  49.    
  50. }
  51.  
  52. int main()
  53. {
  54.     fila *f=fila_cria();
  55.     enfileirar(f,0,3);
  56.     imprime(f);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement