From 110d55e652900cb5b146ae38933e928e96db4867 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Fri, 27 Nov 2020 16:52:44 +0100 Subject: reformat heap.c --- heap.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'heap.c') diff --git a/heap.c b/heap.c index 365d925..7976e52 100644 --- a/heap.c +++ b/heap.c @@ -1,15 +1,16 @@ +#include #include #include -#include + #include "util.h" typedef int T; // https://stackoverflow.com/a/22900767 -#define LEFT(idx) (idx*2+1) -#define RIGHT(idx) (idx*2+2) -#define PARENT(idx) ((idx-1)/2) +#define LEFT(idx) (idx * 2 + 1) +#define RIGHT(idx) (idx * 2 + 2) +#define PARENT(idx) ((idx - 1) / 2) static void swap(T heap[], int i, int j) @@ -38,7 +39,7 @@ fixdown(T heap[], int i, int n) for ( ;; ) { const int l = LEFT(i); const int r = RIGHT(i); - int m = i; + int m = i; if ( l < n && heap[m] < heap[l] ) m = l; @@ -75,8 +76,8 @@ my_heapsort(T a[], int n) // ------------------------------------------- -struct pq { // Priority Queue - T heap[251]; +struct pq { // Priority Queue + T heap[251]; int sz; }; @@ -99,7 +100,7 @@ pq_push(struct pq *pq, T data) } bool -pq_pop(struct pq *pq, T* data) +pq_pop(struct pq *pq, T *data) { if ( pq->sz == 0 ) return false; @@ -113,8 +114,8 @@ pq_pop(struct pq *pq, T* data) // ------------------------------------------- - -void print_heap(T heap[], int n) +void +print_heap(T heap[], int n) { if ( n ) { printf("%d", heap[0]); @@ -124,9 +125,10 @@ void print_heap(T heap[], int n) } } -int main(void) +int +main(void) { -#if 0 // Heap-Testprogramm +#if 0 // Heap-Testprogramm T heap[20] = { 18, 18, 16, 9, 7, 1, 9, 3, 7, 5 }; print_heap(heap, 10); @@ -148,5 +150,3 @@ int main(void) while ( pq_pop(pq, &data) ) printf("%d\n", data); } - - -- cgit v1.3