Add heap data structure

This commit is contained in:
2023-11-13 16:58:32 +01:00
parent bf543330e5
commit 6c88531f68
6 changed files with 191 additions and 0 deletions

View File

@@ -7,3 +7,6 @@ target_link_libraries(window_test LINK_PRIVATE Breeze)
add_executable(cute_tiled_test cute_tiled_test.c)
target_link_libraries(cute_tiled_test LINK_PRIVATE Breeze)
add_executable(heap_test heap_test.c)
target_link_libraries(heap_test LINK_PRIVATE Breeze)

36
engine/tests/heap_test.c Normal file
View File

@@ -0,0 +1,36 @@
#include <breeze.h>
#include <stdio.h>
int main() {
bzLoggerInit();
typedef struct Node {
i32 weight;
} Node;
Node *heap = bzHeapNew(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);
}
bzHeapFree(heap);
return 0;
}