Advertisement
cbmelo97

Untitled

Sep 9th, 2018
2,879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct lista {
  5.     int num;
  6.     struct lista *prox;
  7. }aLista;
  8.  
  9. void Item(aLista **listinha,int i){
  10.     printf("%d -> ",i);
  11.     aLista *ponteiro = listinha[i];
  12.     while(ponteiro->prox != NULL){
  13.         printf("%d", ponteiro->num);
  14.         ponteiro = ponteiro->prox;
  15.     }
  16.     printf("\\\n");
  17. }
  18. void addItem(aLista **listinha, int nk, int hash){
  19.     aLista *ponteiro = malloc(sizeof(aLista));
  20.     ponteiro -> num = nk;
  21.     ponteiro -> prox = NULL;
  22.     if(listinha[hash] == NULL){
  23.         listinha[hash] = ponteiro;
  24.     }else{
  25.         aLista *aux = listinha[hash];
  26.         while (aux->prox != NULL){
  27.             aux = aux->prox;
  28.         }
  29.         aux->prox = ponteiro;
  30.     }
  31. }
  32.  
  33. int main(void){
  34.     int nt,tl,nk,hash;
  35.     aLista *listinha;
  36.     scanf("%d",&nt);
  37.    
  38.     while(nt--){
  39.         aLista *listinha[99] = {NULL};
  40.         scanf("%d" "%d",&tl,&nk);
  41.    
  42.         for(; nk > 0;nk--){
  43.             int chave;
  44.             scanf("%d", &chave);
  45.             int hash = chave % tl;
  46.             addItem(listinha,nk,hash);
  47.         }
  48.  
  49.         for (int i = 0; i < tl; i++){
  50.             Item(listinha, i);
  51.         }
  52.  
  53.         if(nt > 0){
  54.             printf("\n");
  55.         }
  56.     }
  57.     return 0;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement