Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. #define MAX_AEROPORTO 200000 //Máximo de Aeroportos que podem existir
  7. #define MAX_VOO_AERO 150 //Mázimo de Voos por Aeroporto
  8. #define MAX_VOO 750000 //Máximo de Voos
  9. #define COD_AERO 3 //Código do Aeroporto
  10.  
  11. struct aeroportos
  12. {
  13. char codigo_aero[COD_AERO];
  14. };
  15.  
  16. struct voos
  17. {
  18. char codigo_aero_p[COD_AERO];
  19. char codigo_aero_c[COD_AERO];
  20. int hora;
  21. int minuto;
  22. int duracao;
  23. };
  24.  
  25. struct aeroportos aeroporto[MAX_AEROPORTO];
  26. struct voos voo[MAX_VOO];
  27.  
  28. int hashkey_A(int key)
  29. {
  30. key = atoi(aeroporto->codigo_aero);
  31. return key;
  32. }
  33.  
  34. int hashkey_V(int key)
  35. {
  36. key = voo->hora*1000 + voo->minuto * 100;
  37. return key;
  38. }
  39.  
  40. void inserir_A(int key, char codigo_areo[COD_AERO])
  41. {
  42. struct aeroportos *aux_aeroporto = (struct aeroportos*) malloc(sizeof(struct aeroportos));
  43. aux_aeroporto->codigo_aero = codigo_areo;
  44.  
  45. int posicao = hashkey_A(key);
  46.  
  47. while(aux_aeroporto[posicao]!= NULL && aux_aeroporto[posicao].codigo_aero != -1)
  48. {
  49. posicao++;
  50. posicao % MAX_AEROPORTO;
  51. printf("+ novo aeroporto %s \n", codigo_areo);
  52. }
  53. aux_aeroporto[posicao].codigo_aero = codigo_areo;
  54. printf("+ aeroporto %s existe \n", codigo_areo);
  55.  
  56. }
  57.  
  58. void inserir_V(int key, char codigo_aero_p, char codigo_aero_c, int hora, int minuto, int duracao)
  59. {
  60. struct voos *aux_voos = (struct voos*) malloc(sizeof(struct voos));
  61. aux_voos->codigo_aero_c = codigo_aero_c;
  62. aux_voos->codigo_aero_p = codigo_aero_p;
  63. aux_voos->hora = hora;
  64. aux_voos->minuto = minuto;
  65. aux_voos->duracao = duracao;
  66.  
  67. int posicao = hashkey_A(key);
  68.  
  69. while(aux_voos[posicao]!= NULL && aux_voos[posicao].codigo_aero_p != -1)
  70. {
  71. posicao++;
  72. posicao % MAX_AEROPORTO;
  73. printf("+ novo voo %s %s %d:%d \n", codigo_aero_p,codigo_aero_c,hora,minuto);
  74. }
  75. aux_voos[posicao].codigo_aero_p = codigo_areo_p;
  76. printf("+ aeroporto %s existe \n", codigo_areo);
  77. }
  78.  
  79. int main() {
  80. printf("Hello, World!\n");
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement