1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include "Heap.h"
void HeapSort(int* a, int n) { for (int i = (n - 1 - 1) / 2; i >= 0; --i) { AdjustDown(a,n,i); }
int end = n - 1; while (end > 0) { swap(&a[0], &a[end]); AdjustDown(a, end, 0); --end; } } void test2() { int arr[] = { 27,15,19,18,28,34,65,49,25,37 }; HeapSort(arr, sizeof(arr) / sizeof(Hpdatatype)); }
void test1() { int arr[] = { 27,15,19,18,28,34,65,49,25,37 }; Heap hp; HeapInit(&hp, arr, sizeof(arr) / sizeof(Hpdatatype)); HeapPush(&hp, 3); HeapPush(&hp, 66); }
int main() { test1();
return 0; }
|