Advertisement
luciana1237

Untitled

Aug 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.17 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> /* rand && srand() */
  9. #include <unistd.h>
  10.  
  11.  
  12. #define MAX_PISTAS 4
  13. #define MAX_PRATELEIRAS 3
  14.  
  15. typedef struct Queue
  16. {
  17.     int pistas,prateleiras;
  18.     struct Queue *begin,*end;
  19. }queue;
  20.  
  21. int len=0;
  22.  
  23. int random_id()
  24. {
  25.     srand(time(NULL));
  26.  
  27.     return rand () % 100;
  28. }
  29.  
  30. queue *queue_create(void)
  31. {
  32.     queue *q = (queue *) malloc(sizeof(queue));
  33.    
  34.     if (q!= NULL)
  35.         q->begin = NULL;
  36.         q->end  = NULL;
  37.     return q;
  38. }
  39. bool isEmpty(queue **q)
  40. {
  41.     return ()
  42. }
  43.  
  44.  
  45. queue *enfileirar(queue **q,int IDaviao)
  46. {
  47.     queue *novo = (queue *) malloc(sizeof(queue)); /*alocando memoria dinamicamente */
  48.    
  49.     int y,i,t_clock,r;
  50.    
  51.     if (novo == NULL) /* se ocorrer algum erro de alocacao */
  52.     {
  53.         fprintf(stderr,"erro de alocacao\n");
  54.         exit( 1 );
  55.     }
  56.    
  57.     srand(time(NULL));
  58.    
  59.     r = rand()%4;
  60.    
  61.     for(t_clock =r; t_clock >=0; t_clock--){
  62.        
  63.         sleep( 1 );
  64.         printf("\n\tTempo Para aterrisagem: { 00 : 0%d } \n",t_clock);
  65.        
  66.         if (t_clock == 0)
  67.         {
  68.             if (r == 1 || r == 2 || r == 3 || r==4)
  69.             {
  70.                 if (novo != NULL)
  71.                     novo->begin = NULL;
  72.                     novo->pistas = IDaviao;
  73.                    
  74.                     novo->end =(*q);
  75.                    
  76.                     if ((*q)->end == NULL)
  77.                     {
  78.                         printf("\nVAZIA\n");
  79.                         (*q)->begin = novo;
  80.                     }else
  81.                     {
  82.                         printf("\nTEM\n");
  83.                         queue *aux;
  84.                         aux = (*q)->begin;
  85.                         for(; aux != NULL; aux=aux->begin)
  86.                        
  87.                         (*q)->end = novo;
  88.                     }
  89.             }else if (r ==0)
  90.             {
  91.                 printf("\nAVIAO CAIU: %d \n",IDaviao);
  92.                 len--;
  93.             }
  94.         }
  95.        
  96.     }
  97.     len++;
  98.     if (len > MAX_PISTAS)
  99.         printf("\nFilas Excedidas \n");
  100.        
  101.     return novo;
  102. }
  103.  
  104. void show(queue **q)
  105. {
  106.     int i=0;
  107.     for(; i <len; i++)
  108.         printf("PISTA [%d] -> ID: %d \n",i,(*q)->pistas);
  109. }
  110.  
  111. int main()
  112. {
  113.     queue *q = queue_create();
  114.     int id,opc;
  115.    
  116.     if(q!= NULL)
  117.         for(;;){
  118.             id = random_id();
  119.             printf("\n\t-> id [ %d ] \n",id);
  120.            
  121.             printf("\n\t_(0)---------- [SAIR]");
  122.             printf("\n\t_(1)---------- [ PUSH ]");
  123.             printf("\n\t_(2)---------- [ SHOW ] \n");
  124.             printf("\t> "); scanf("%d",&opc);
  125.            
  126.             switch(opc){
  127.                 case 0:
  128.                     exit( 0 );
  129.                 default:
  130.                     break;
  131.                 case 1:
  132.                     q=enfileirar(&q,id);
  133.                     break;
  134.                 case 2:
  135.                     show(&q);
  136.                     break;
  137.             }
  138.         }
  139.  
  140.            
  141.     return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement