MinHeap Class
Lektion 3 von 14 im Kurs Heaps & Priority Queues - Datenstrukturen-Serie #7 von Coddy.
Aufgabe
EinfachSchreiben Sie eine Klasse MinHeap mit einem constructor, der keine Eingabewerte erhält.
Initialisieren Sie ein einzelnes Feld heap als ein leeres Array (oder das Äquivalent Ihrer Sprache für eine dynamische Ganzzahlen-Liste).
Probier es selbst
#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;
}