Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /* Estruturas de Dados 2
  2. * Lista 2 - Questão 1 - a)
  3. * Jonas Bastos Antunes (201500018673)
  4. * Jonas Ferreira Santos (201420006265)
  5. * Werthen de Castro Santos (201500018486)
  6. */
  7.  
  8. #include <stdio.h>
  9. int SIZE = 11;
  10.  
  11. int hash(int c, int s)
  12. {
  13. return c%s;
  14. }
  15.  
  16. int inserir(int chave, int array[][SIZE], int row)
  17. {
  18. int column = 0;
  19.  
  20. while (array[row][column] != -1)
  21. {
  22. column++;
  23. }
  24. array[row][column] = chave;
  25.  
  26. }
  27.  
  28. int main()
  29. {
  30. int chaves[] = {24, 76, 39, 61, 25, 10, 16, 70, 53};
  31. int CHAVES_SIZE = 9;
  32.  
  33. int arquivo[SIZE][SIZE];
  34.  
  35. int i = 0;
  36. int j = 0;
  37.  
  38. //inicialização
  39. for (i=0; i<SIZE; i++)
  40. {
  41. for (j=0; j<SIZE; j++)
  42. arquivo[i][j] = -1;
  43. }
  44.  
  45. for (i=0; i<CHAVES_SIZE; i++)
  46. {
  47. inserir(chaves[i], arquivo, hash(chaves[i], SIZE));
  48. }
  49.  
  50. for (i=0; i<SIZE; i++)
  51. {
  52. printf("[%d] : ", i);
  53. for (j=0; j<SIZE; j++)
  54. {
  55. if (arquivo[i][j] == -1 && j!=0) break;
  56. if (j>0) printf(" -> ");
  57. printf("%d", arquivo[i][j]);
  58. }
  59. printf("\n");
  60. }
  61. printf("\n");
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement