1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| typedef struct L {
char mot[100];
char donnee[100];
struct L *next;
}Liste;
struct HashTable {
int mod; // Nombre d'éléments de la table
Liste *table; // Pointeur sur la table allouée
};
// déclaration des fonctions
unsigned hash_cle(char *chaine);
int fonctHachage(liste_mot* );
void hashTableInit(HashTable ht, int mod);
void hashTableInit(HashTable& ht, int mod)
{
// Nombre d'éléments de la table
ht.mod = mod;
// Allocation de la table
if ((ht.table = (Liste*) malloc(mod * sizeof(Liste))) == 0) {
fprintf(stderr, "Plus de mémoire\n");
exit(1);
}
// Initialisation de la table
// Au début toutes les listes sont vides
for (int i = 0; i < mod; i++)
ht.table[i] = 0; // Liste vide là il ya l'erreur 1
}
// Affichage complet d'une table de hachage
void hashTablePrint(HashTable& ht)
{
for (int i = 0; i < ht.mod; i++)
//if (ht.table[i] != 0) {
// printf("Entrée %d\n", i);
listePrint(ht.table[i]);
}
void listePrint(Liste l)
{
while (l != NULL) {
printf("%d : %s", l->mot, l->donnee);
l = l->next;
}
}
int main(int argc, char *argv[])
{ char c;
int A;
int val;
liste_mot* s =NULL;
HashTable ht;
// Initialisation de la table
hashTableInit(ht, 110);
val=fonctHachage(s);
A=nbr_mot(s);
// Affichage de la liste
hashTablePrint(ht);
scanf("%c",c);
return 0;
} |
Partager