HashMap Class
Coddy의 Hash Table - 자료구조 시리즈 #4 코스 레슨 — 14개 중 3번째.
챌린지
쉬움입력을 받지 않는 생성자를 가진 HashMap 클래스를 작성하세요.
생성자에서 다음 세 가지 필드를 초기화하십시오:
capacity를 10으로 설정합니다.buckets를 10개의 빈 리스트(체이닝을 위해 버킷당 하나씩)를 포함하는 배열로 설정합니다.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;
}