HashMap Class
الدرس 3 من 14 في دورة جداول الهاش - سلسلة هياكل البيانات #4 على Coddy.
التحدي
سهلاكتب فئة HashMap مع constructor لا يأخذ أي مدخلات.
في الـ constructor، قم بتهيئة ثلاثة حقول:
capacityمضبوطة على 10.bucketsمضبوطة على مصفوفة من 10 قوائم فارغة (واحدة لكل bucket، من أجل الربط/chaining).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;
}