Add heap data structure
This commit is contained in:
@@ -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
36
engine/tests/heap_test.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user