SBDP01/heap.h
2018-10-21 13:04:41 +02:00

32 lines
657 B
C

#ifndef HEAP_H
#define HEAP_H
#include "record.h"
#include <stdlib.h>
typedef struct {
void** records;
size_t max;
size_t current;
int (*compare)(const void* a, const void* b);
} heap_t;
unsigned heap_left(unsigned node);
unsigned heap_right(unsigned node);
unsigned heap_parent(unsigned node);
void heap_init(heap_t* heap, size_t size, int (*compare)(const void* a, const void *b));
void heap_free(heap_t* heap);
void heap_insert(heap_t* heap, void* record);
void heap_remove(heap_t* heap, unsigned n);
void* heap_min(heap_t* heap);
void* heap_pop(heap_t* heap);
void heap_print(heap_t* heap, void (*print)(void* record));
#endif