Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Estruturas de Dados 2
- * Lista 2 - Questão 1 - a)
- * Jonas Bastos Antunes (201500018673)
- * Jonas Ferreira Santos (201420006265)
- * Werthen de Castro Santos (201500018486)
- */
- #include <stdio.h>
- int SIZE = 11;
- int hash(int c, int s)
- {
- return c%s;
- }
- int inserir(int chave, int array[][SIZE], int row)
- {
- int column = 0;
- while (array[row][column] != -1)
- {
- column++;
- }
- array[row][column] = chave;
- }
- int main()
- {
- int chaves[] = {24, 76, 39, 61, 25, 10, 16, 70, 53};
- int CHAVES_SIZE = 9;
- int arquivo[SIZE][SIZE];
- int i = 0;
- int j = 0;
- //inicialização
- for (i=0; i<SIZE; i++)
- {
- for (j=0; j<SIZE; j++)
- arquivo[i][j] = -1;
- }
- for (i=0; i<CHAVES_SIZE; i++)
- {
- inserir(chaves[i], arquivo, hash(chaves[i], SIZE));
- }
- for (i=0; i<SIZE; i++)
- {
- printf("[%d] : ", i);
- for (j=0; j<SIZE; j++)
- {
- if (arquivo[i][j] == -1 && j!=0) break;
- if (j>0) printf(" -> ");
- printf("%d", arquivo[i][j]);
- }
- printf("\n");
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement