33 lines
861 B
C
33 lines
861 B
C
#include <stdio.h>
|
|
|
|
#include "data_structures/heap.h"
|
|
#include "algorithms/sort_heap.h"
|
|
|
|
int compare_nodes(dlos_ComparableNode *a, dlos_ComparableNode *b) {
|
|
int left = *((int*) a->value);
|
|
int right = *((int*) b->value);
|
|
if (left > right) {
|
|
return -1;
|
|
} else if (left == right) {
|
|
return 0;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
int test_size = 10;
|
|
int data_storage[] = {73, 6, 57, 88, 60, 42, 83, 72, 48, 85};
|
|
dlos_ComparableNode a[test_size];
|
|
for (int i = 0; i < test_size; i++) {
|
|
a[i].value = &data_storage[i];
|
|
}
|
|
dlos_heapsort_array(a, test_size, compare_nodes);
|
|
for (int i = 0; i < test_size; i++) {
|
|
if (i == 0) printf("sorted: ");
|
|
printf("%d, ", *((int*) a[i].value));
|
|
if (i == test_size - 1) printf("\n");
|
|
}
|
|
return 0;
|
|
}
|