MinHeap Class
Lesson 3 of 14 in Coddy's Heaps & Priority Queues - Data Structures Series #7 course.
Challenge
EasyWrite a class MinHeap with a constructor that gets no input.
Initialize a single field heap as an empty array (or your language's equivalent for a dynamic integer list).
Try it yourself
#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;
}