Add another option for c heapsort, minor refactors, update docs

This commit is contained in:
2025-10-08 00:08:46 -05:00
parent 3fcd09e7c0
commit 6d84849ce8
5 changed files with 70 additions and 28 deletions

View File

@@ -1,8 +1,18 @@
#include "../data_structures/heap.h"
#include "sort_heap.h"
void dlos_sort_heap(dlos_Heap *h) {
int original_size = h->size;
void dlos_heapsort_array(dlos_ComparableNode *arr, int size, int (*compare)()) {
dlos_Heap heap = { .size = size, .arr = arr, .arr_size = size, .compare = compare };
dlos_max_heap(&heap);
for (int i = heap.size - 1; i > 0; i--) {
dlos_node_swap(heap.arr, 0, i);
heap.size -= 1;
dlos_sift_down(0, &heap);
}
}
// already have the heap, want to sort its array
void dlos_heapsort_heap(dlos_Heap *h) {
for (int i = h->size - 1; i > 0; i--) {
dlos_node_swap(h->arr, 0, i);
h->size -= 1;