Add another option for c heapsort, minor refactors, update docs
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user