added a generic min heap with a custom comparator

This commit is contained in:
Semere M. Mebrahtom 2026-04-01 23:19:17 +02:00
parent 6772407a3c
commit b1b32525a5
Signed by: semere
GPG key ID: 7FC937214DF30488
4 changed files with 119 additions and 14 deletions

View file

@ -66,4 +66,21 @@ typedef struct s_state
t_args *parse_arguments(int count, char **args);
// heap.c
# ifndef HEAP_SIZE
# define HEAP_SIZE 25
# endif
typedef struct s_minheap
{
int length;
void *array[HEAP_SIZE];
int (*cmp)(void *, void *);
} t_minheap;
t_minheap *init_heap(int (*cmp)(void *, void *));
void *peek(t_minheap *heap);
void enqueue(t_minheap *heap, void *val);
void *dequeue(t_minheap *heap);
#endif