Advertisement
luciana1237

Untitled

Aug 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. /*----------------------*/
  2. /*| FILAS.C            |*/
  3. /*----------------------*/
  4.  
  5. #include <stdio.h> /* I/O */
  6. #include <stdlib.h> /* malloc*/
  7. #include <stdbool.h> /*bool*/
  8. #include <time.h>
  9.  
  10. #define MAX_PISTAS 4
  11. #define MAX_PRATELEIRAS 3
  12.  
  13. typedef struct Queue
  14. {
  15.     int pistas,prateleiras;
  16.     struct Queue *begin,*end;
  17. }queue;
  18.  
  19. int len=0;
  20.  
  21. int random_id()
  22. {
  23.     srand(time(NULL));
  24.  
  25.     return rand () % 100;
  26. }
  27.  
  28. queue *queue_create(void)
  29. {
  30.     queue *q = (queue *) malloc(sizeof(queue));
  31.    
  32.     if (q!= NULL)
  33.         q->begin = NULL;
  34.         q->end  = NULL;
  35.     return q;
  36. }
  37.  
  38.  
  39. queue *enfileirar(queue **q,int IDaviao)
  40. {
  41.     queue *novo = (queue *) malloc(sizeof(queue)); /*alocando memoria dinamicamente */
  42.    
  43.     if (novo == NULL) /* se ocorrer algum erro de alocacao */
  44.     {
  45.         fprintf(stderr,"erro de alocaca\n");
  46.         exit( 1 );
  47.     }
  48.     if (novo != NULL)
  49.         novo->begin = NULL;
  50.         novo->pistas = IDaviao;
  51.         novo->end = (*q);
  52.    
  53.         if ((*q)->end == NULL)
  54.         {
  55.             printf("\nVAZIA\n");
  56.             (*q)->begin = novo;
  57.         }else
  58.         {
  59.             printf("\nTEM\n");
  60.             (*q)->end = novo;
  61.         }
  62.         len++;
  63.         if (len ==3)
  64.             printf("\nFILA EXcedida \n");
  65.         return novo;
  66. }
  67.  
  68. void show(queue **q)
  69. {
  70.     int i=0;
  71.     for(; i <1; i++)
  72.         printf("[ %d ] \n",(*q)->pistas);
  73. }
  74.  
  75. int main()
  76. {
  77.     queue *q = queue_create();
  78.     int id;
  79.     id = random_id();
  80.     printf("-> id [ %d ] \n",id);
  81.     if(q!= NULL)
  82.         q=enfileirar(&q,id);
  83.         q=enfileirar(&q,id);
  84.         q=enfileirar(&q,id);
  85.         if (q)
  86.             show(&q);
  87.    
  88.    
  89.            
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement