HashMap Class
Lesson 3 of 14 in Coddy's Hash Tables - Data Structures Series #4 course.
Challenge
EasyWrite a class HashMap with a constructor that takes no input.
In the constructor, initialize three fields:
capacityset to 10.bucketsset to an array of 10 empty lists (one per bucket, for chaining).countset to 0.
Try it yourself
#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;
}