heap start

This commit is contained in:
bronku 2025-10-22 00:12:26 +02:00
parent b3b532bb14
commit 7916f181c5
5 changed files with 63 additions and 9 deletions

28
heap.c Normal file
View file

@ -0,0 +1,28 @@
#include "heap.h"
#include "status_codes.h"
int heap_push(heap* h, heap_record* in)
{
if (h->length >= h->capacity) {
return NO_SPACE;
}
int index = h->length;
h->length++;
heap_record* last = h->location;
last += index;
*last = *in;
if (index == 0) {
return SUCCESS;
}
// check if violated heap property
heap_record* parent = h->location;
parent += ((index - 1) / 2);
while (parent->g > last->g) {
// just swap them, and check again?
}
// swim up
return SUCCESS;
}