-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
38 lines (28 loc) · 921 Bytes
/
queue.h
File metadata and controls
38 lines (28 loc) · 921 Bytes
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
#ifndef QUEUE_H
#define QUEUE_H
#pragma once
#include <stdbool.h>
void mem_swap(void* dat, int j, int k, int type_size);
// min heap priority queue
// create generic priority_queue
// everything is void* again!
// comparator function needs to be passed in at initialization.
//
// properties:
// 1. every parent node has a value less than or equal to its children
// min value of the heap is always at the root
// 2. min heap is a complete binary tree
// (all levels are filled except last)
typedef struct {
void *data;
int type_size;
int length, capacity;
int (*cmp)(const void *, const void *); // cmp for the generic data type stored in queue
} queue;
queue* init_queue(int tsize, int c, int (*comparator)(const void *, const void *));
void queue_insert(queue *q, void *v);
void* pop_min(queue *q);
void heapify(queue *q, int j);
bool queue_is_empty(queue *q);
void destroy_queue(queue *q);
#endif