HashMap Class
Lektion 3 von 14 im Kurs Hash-Tabellen – Datenstrukturen-Serie #4 von Coddy.
Aufgabe
EinfachSchreiben Sie eine Klasse HashMap mit einem Konstruktor, der keine Eingabe entgegennimmt.
Initialisieren Sie im Konstruktor drei Felder:
capacitygesetzt auf 10.bucketsgesetzt auf ein Array von 10 leeren Listen (eine pro Bucket, für das Chaining).countgesetzt auf 0.
Probier es selbst
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hashmap.h"
int main() {
HashMap h;
HashMap_init(&h);
char line[256];
while (fgets(line, sizeof(line), stdin)) {
line[strcspn(line, "\r\n")] = '\0';
char* cmd = strtok(line, " \t");
if (!cmd) continue;
if (strcmp(cmd, "state") == 0) { printf("%d %d %d\n", h.capacity, h.capacity, h.count); }
}
return 0;
}