Menu
Coddy logo textTech

HashMap Class

Lektion 3 von 14 im Kurs Hash-Tabellen – Datenstrukturen-Serie #4 von Coddy.

challenge icon

Aufgabe

Einfach

Schreiben Sie eine Klasse HashMap mit einem Konstruktor, der keine Eingabe entgegennimmt.

Initialisieren Sie im Konstruktor drei Felder:

  • capacity gesetzt auf 10.
  • buckets gesetzt auf ein Array von 10 leeren Listen (eine pro Bucket, für das Chaining).
  • count gesetzt 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;
}

Alle Lektionen in Hash-Tabellen – Datenstrukturen-Serie #4