Files
PixelDefense/engine/tests/heap_test.c

55 lines
1.1 KiB
C

#include <breeze.h>
#include <stdio.h>
int main() {
bzLoggerInit();
typedef struct Node {
i32 weight;
} Node;
Node *heap = bzHeapCreate(Node, 20);
bzHeapPush(heap, (Node) {3});
bzHeapPush(heap, (Node) {2});
bzHeapPush(heap, (Node) {1});
bzHeapPush(heap, (Node) {15});
bzHeapPush(heap, (Node) {2});
bzHeapPush(heap, (Node) {8});
bzHeapPush(heap, (Node) {10});
bzHeapPop(heap);
for (int i = 0; i < bzHeapSize(heap); i++) {
printf("%d ", heap[i].weight);
}
printf("\n\n");
while (!bzHeapIsEmpty(heap)) {
Node node = bzHeapPop(heap);
printf("%d\n", node.weight);
}
printf("\n\n");
bzHeapDestroy(heap);
heap = bzHeapCreate(Node, 10);
bzHeapPush(heap, (Node) {3});
bzHeapPush(heap, (Node) {8});
bzHeapPush(heap, (Node) {10});
bzHeapPush(heap, (Node) {5});
bzHeapPush(heap, (Node) {12});
bzHeapPush(heap, (Node) {7});
heap[3].weight = 20;
bzHeapUpdate(heap, 3);
while (!bzHeapIsEmpty(heap)) {
Node node = bzHeapPop(heap);
printf("%d ", node.weight);
}
bzHeapDestroy(heap);
return 0;
}