HashMap Class
Coddyの「ハッシュテーブル - データ構造シリーズ #4」コースのレッスン 3/14。
チャレンジ
簡単引数を取らないコンストラクタを持つ HashMap クラスを作成してください。
コンストラクタ内で、以下の3つのフィールドを初期化します:
capacityを 10 に設定します。bucketsを 10個の空のリスト(チェイン法のために、バケットごとに1つ)の配列に設定します。countを 0 に設定します。
自分で試してみよう
#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;
}