Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <time.h>
  5.  
  6.  
  7. typedef struct Fila {
  8.    
  9.     int id,size,av1,av2,av3;
  10.     struct Fila *prox;
  11.    
  12. }fila;
  13.  
  14. fila *fila_cria(void)
  15. {
  16.     fila *pointer = (fila *) malloc(sizeof(fila));
  17.    
  18.     if (pointer != NULL)
  19.         pointer->size =0;
  20.        
  21.     return pointer;
  22. }
  23.  
  24. bool isEmpty(fila *p)
  25. {
  26.     if (p->prox == NULL)
  27.         return 0;
  28.     else
  29.         return 1;
  30. }
  31.  
  32. fila *fila_push(fila **p,int valor)
  33. {
  34.     fila *_novo_elemento = (fila *) malloc(sizeof(fila));
  35.     _novo_elemento->size =0;
  36.    
  37.     if (_novo_elemento == NULL)
  38.     {
  39.         fprintf(stderr," Erro de Alocacao \n"); exit( 0 );
  40.     }
  41.    
  42.     srand(time(NULL) *5);
  43.    
  44.     _novo_elemento->id = rand() % 10000;
  45.    
  46.     if (!isEmpty(p))
  47.     {
  48.         printf("--vazia---\n");
  49.        
  50.         _novo_elemento->av1 = valor;
  51.        
  52.     }else {
  53.         while(_novo_elemento != NULL){
  54.            
  55.             _novo_elemento = _novo_elemento->prox;
  56.             _novo_elemento->av1 = valor;
  57.            
  58.             _novo_elemento->prox = (*p);
  59.         }
  60.     }
  61.     _novo_elemento->size++;
  62.     return _novo_elemento;
  63. }
  64.  
  65. void _imprime_fila(fila **p)
  66. {
  67.     fila *pointer;
  68.     pointer = (*p);
  69.    
  70.     if (!isEmpty(*p))
  71.         for(; pointer != NULL; pointer = pointer->prox){
  72.             printf("%d \n",pointer->av1);
  73.         }
  74. }
  75.  
  76. int main()
  77. {
  78.     fila *f;
  79.     f = fila_push(&f,3);
  80.     _imprime_fila(&f);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement