Menu
Coddy logo textTech

Classe HashMap

Lezione 3 di 14 del corso Tabelle hash - Serie sulle strutture dati #4 di Coddy.

challenge icon

Sfida

Facile

Scrivi una classe HashMap con un costruttore che non accetta input.

Nel costruttore, inizializza tre campi:

  • capacity impostato a 10.
  • buckets impostato a un array di 10 liste vuote (una per bucket, per il concatenamento).
  • count impostato a 0.

Provalo tu

#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;
}

Tutte le lezioni di Tabelle hash - Serie sulle strutture dati #4

Esercitati da solo: Compilatore C online