Advertisement
luciana1237

av...

Aug 9th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. /* FILAS em C Segue o padrC#o LIFO */
  2. /*Last In First Out = Ultimo a entrar e o ultimo a sair */
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdbool.h>
  7. #include <time.h>
  8. #include <unistd.h>
  9.  
  10. #define MAX_PRATELEIRAS 10
  11. #define MAX_PISTAS 10
  12.  
  13. int size=0;
  14.  
  15. struct t_clock
  16. {
  17.     int Mm,Hh,Hours,Minutes,Secunds;
  18. };
  19.  
  20. typedef struct t_celula
  21. {
  22.     int prateleiras[MAX_PRATELEIRAS],pistas[MAX_PISTAS],values;
  23.    
  24.     struct t_celula *prox;
  25.     struct t_celula *begin;
  26.     struct t_celula *end;
  27. }queue;
  28.  
  29. typedef struct t_clock t_time;
  30.  
  31.  
  32. int random_id()
  33. {
  34.     srand(time(NULL));
  35.    
  36.     return rand() %1000;
  37. }
  38.  
  39. bool isEmpty(queue **q)
  40. {
  41.     return((*q)->end == NULL);
  42. }
  43.  
  44. queue *queue_create()
  45. {
  46.     queue * q = (queue *) malloc(sizeof(queue)); /* Alocando memoria dinamicamente */
  47.    
  48.     if (q != NULL)
  49.         q->prox = NULL;
  50.         q->begin= NULL;
  51.         q->end = NULL;
  52.     return q;
  53. };
  54.  
  55.  
  56. queue *enfileirar(queue **q,int IdAviao)
  57. {
  58.     queue *novo_elemento = (queue *) malloc(sizeof(queue));
  59.     t_time *clock_t = (t_time *) malloc(sizeof(t_time));
  60.     clock_t->Hh =0;
  61.    
  62.     int r,y;
  63.    
  64.     if (novo_elemento == NULL)
  65.     {
  66.         fprintf(stderr,"erro \n");
  67.         exit( 0 );
  68.     }
  69.     if (novo_elemento != NULL)
  70.    
  71.         novo_elemento->values = IdAviao;
  72.         novo_elemento->prox = NULL;
  73.        
  74.         srand(time(NULL));
  75.        
  76.         r = rand() %4;
  77.        
  78.         if (r == 1 || r==2 || r==3 || r==4){
  79.             clock_t->Mm = rand() %10;
  80.             for(y=clock_t->Mm; y >=0; y--){
  81.                 sleep( 1 );
  82.                 printf("\nTEMPO PREVISTO PARA DECOLAGEM %d \n",y);
  83.                 if(y == 0)
  84.                     if((*q)->end == NULL){
  85.                         printf("\n---VAZIA---\n");
  86.                         (*q)->begin = novo_elemento;
  87.                     }else{
  88.                         printf("\nTEM\n");
  89.                         (*q)->end->prox = novo_elemento;
  90.                     }  
  91.             }
  92.         }else
  93.         {
  94.             printf("AVIAO CAIU\n");
  95.         }
  96.         size++;
  97.         (*q)->end = novo_elemento;
  98.         return novo_elemento;
  99. }
  100.  
  101. void imprime(queue **q)
  102. {
  103.     queue *pointer;
  104.     //pointer =(*q);
  105.     int i;
  106.     for(i=0; i <size; i++)
  107.         printf("[ %d ]\n",(*q)->values);
  108. }
  109.  
  110. int main()
  111. {
  112.     int ID,opc;
  113.    
  114.     ID = random_id();
  115.     printf("ID -> %d \n",ID);
  116.    
  117.     for(;;){
  118.         printf("\n\t(0)_____________[ SAIR ] ");
  119.         printf("\n\t(1)_____________[ ENFILEIRAR ]");
  120.         printf("\n\t(2)_____________[ IMPRIMIR ]\n");
  121.         printf("> "); scanf("%d",&opc);
  122.        
  123.         switch(opc){
  124.             case 0:
  125.                 exit( 0 );
  126.             default:
  127.                 break;
  128.             case 1:
  129.                 enfileirar(&q,)
  130.         }
  131.     }
  132.     queue *q = queue_create();
  133.     q=enfileirar(&q,ID);
  134.     q=enfileirar(&q,ID);
  135.     imprime(&q);
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement