MinHeap Class
Coddy의 힙 & 우선순위 큐 - 자료구조 시리즈 #7 코스 레슨 — 14개 중 3번째.
챌린지
쉬움입력을 받지 않는 생성자를 포함한 MinHeap 클래스를 작성하세요.
heap이라는 단일 필드를 빈 배열(또는 해당 언어에서 동적 정수 리스트에 해당하는 것)로 초기화하세요.
직접 해보기
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "minheap.h"
int main() {
MinHeap h;
MinHeap_init(&h);
char line[1024];
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\n", h.count); }
}
return 0;
}