Advertisement
luciana1237

Untitled

Jul 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5.  
  6. #define MAX 10
  7.  
  8. struct Info {
  9.     int vetor[MAX],x,v[MAX],prateleiras1[MAX];
  10.     char str[MAX];
  11.  
  12. };
  13.  
  14. typedef struct Info info;
  15.  
  16. typedef struct Celula {
  17.    
  18.     info *dados;
  19.     struct Celula *ant;
  20.     struct Celula *prox;
  21.    
  22. }cel;
  23.  
  24. int size =0x0;
  25.  
  26. int random_id()
  27. {
  28.     srand(time(NULL));
  29.    
  30.     return rand() %1000;
  31. }
  32.  
  33. cel *cria_cel(void)
  34. {
  35.     cel *c = (cel *) malloc(sizeof(cel));
  36.    
  37.     if (c!= NULL)
  38.         c->ant = NULL;
  39.         c->prox = NULL;
  40.     return c;
  41. }
  42.  
  43. bool isEmpty(cel *c)
  44. {
  45.     return (c->prox == NULL);
  46. }
  47.  
  48. bool Push(cel **c,int pos,info *idAviao)
  49. {
  50.     cel *novo = (cel *) malloc(sizeof(cel));
  51.     cel *aux;
  52.     int y,r,t_clock,Mm;
  53.    
  54.     t_clock = rand() %60;
  55.    
  56.     srand(time(NULL));
  57.    
  58.     if (novo == NULL)
  59.     {
  60.         fprintf(stderr," erro "); exit( 0 );
  61.     }
  62.    
  63.     novo->dados = p;
  64.     novo->prox = NULL;
  65.     novo->ant = (*c);
  66.    
  67.     for(y=t_clock; y >=0; y--){
  68.         sleep( 1 )  /* Para Windows Sleep(1000); */
  69.        
  70.         printf("\n\t-=========================================-\n");
  71.         printf("\n\t|TEMPO PREVISTO PARA PROXIMA ATERRISAGEM  |\n\n");
  72.         printf("\n\t| TEMPO: \t{ 00 : %d }                   |\n",y);
  73.         printf("\n\t-=========================================- \n");
  74.        
  75.         if (y==0){
  76.             Mm=Mm+1;
  77.             if (Mm == 1)
  78.                 r = rand() %6;
  79.                
  80.                 if (r == 1 || r==2 || r== 3 || r==4 || r==5){
  81.                     sleep( 2 ); /* Para Windows Sleep(2000); */
  82.                    
  83.                     printf("\n\t********************************\n");
  84.                     printf("\n\t|[+] AVIAO => %d Aterrisando [+]|\n",idAviao);
  85.                     printf("\n\t********************************");
  86.                    
  87.                     novo->prateleiras1[ pos ] = IdAviao;
  88.                    
  89.                     sleep( 2 );
  90.                    
  91.                     printf("\nAVIAO => %d DECOLADO COM SUCESSO \n",IdAviao);
  92.                    
  93.                     if(isEmpty(*c))
  94.                         (*c)->prox =novo;
  95.                     else
  96.                         printf("tem");
  97.                         aux = (*c)->prox;
  98.        
  99.                         while(aux->prox != NULL){
  100.                             aux = aux->prox;
  101.                         }
  102.                         aux->prox = novo;
  103.                         aux->ant = aux;
  104.                 }
  105.             }
  106.         }
  107.    
  108.     size++;
  109.     return true;
  110. }
  111.  
  112. void ShowList(cel **c)
  113. {
  114.     size_t count=0;
  115.  
  116.     cel *pointer;
  117.     pointer = (*c)->prox;
  118.  
  119.     if(isEmpty(*c))
  120.         printf("----LISTA VAZIA----");
  121.     if (!isEmpty(*c))
  122.         for(; count <= size; count++)
  123.             printf("%d \n",pointer->dados->vetor[count]);
  124. }
  125.  
  126. int sizeList(cel **c)
  127. {
  128.     size_t count = 0;
  129.  
  130.     if (!isEmpty(*c)){
  131.         cel *pointer = (*c)->prox;
  132.         for(; pointer != NULL; pointer =pointer->prox)
  133.             count++;
  134.     }if (isEmpty(*c))
  135.         printf("----LISTA VAZIA----");
  136.  
  137.  
  138.     return count;
  139. }
  140.  
  141.  
  142. void libera_lista(cel **c)
  143. {
  144.     cel *no;
  145.     if (!isEmpty(*c)){
  146.         while((*c)->prox != NULL){
  147.             no = (*c);
  148.             (*c) = (*c)->prox;
  149.            
  150.             free(no);
  151.             size--;
  152.         }
  153.     }if(isEmpty(*c))
  154.         printf("\n ----LISTA VAZIA----\n");
  155. }
  156.  
  157. int main()
  158. {
  159.  
  160.     int _opc,elem,pos,tam_v,x;
  161.     info p;
  162.  
  163.     cel *c = cria_cel();
  164.  
  165.     for(;;){
  166.         x= random_id();
  167.        
  168.         printf("\n\t(0)---------- SAIR ");
  169.         printf("\n\t(1)---------- INSERIR ELEMENTO NO INICIO DA LISTA (PUSH) ");
  170.         printf("\n\t(3)---------- IMPRIMIR ");
  171.         printf("\n\t(6)---------- LIBERAR LISTA \n");
  172.        
  173.         printf("> "); scanf("%d",&_opc);
  174.        
  175.         switch(_opc){
  176.             case 0:
  177.                 exit( 0 );
  178.                // break;
  179.             default:
  180.                 fprintf(stdout,"[-] COMANDO INVALIDO!!! [-]");
  181.                 break;
  182.             case 1:
  183.                 printf("Informe a posicao do vetor:\n ");
  184.                 printf("> "); scanf("%d",&pos);
  185.                 //p.prateleiras1[pos] = elem;
  186.                 Push(&c,pos,x);
  187.                 break;
  188.             case 2:
  189.                 printf("\n POP \n");
  190.                 Pop(&c);
  191.                 break;
  192.             case 3:
  193.                 ShowList(&c);
  194.                 break;
  195.             case 4:
  196.                 tam_v = sizeList(&c);
  197.                 printf("\n TAMANHO DA LISTA -> [ %d ]\n",tam_v);
  198.                 break;
  199.             case 5:
  200.                 printf("Digite o item de busca: ");
  201.                 scanf("%d",elem);
  202.                 SearchList(&c,elem);
  203.                 break;
  204.             case 6:
  205.                 libera_lista(&c);
  206.                 break;
  207.         }
  208.        
  209.     }
  210.     return 0;
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement