forked from AllAlgorithms/c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
57 lines (46 loc) · 1.26 KB
/
Copy pathqueue.h
File metadata and controls
57 lines (46 loc) · 1.26 KB
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
48
49
50
51
52
53
54
55
56
57
#ifndef QUEUE_H
#define QUEUE_H
#define EQUEUEFULL 1
typedef void *(*fn_node_data_init) (void);
typedef void (*fn_node_data_destroy) (void *data);
struct queue {
unsigned int max_size;
unsigned int size;
struct queue_node *head;
struct queue_node *tail;
};
struct queue_node {
void *data;
struct queue_node *next;
};
/*
* Create a new queue object
*/
struct queue *queue_init(const unsigned int max_size);
/*
* Destroy an existing queue object
*
* fn_node_data_destroy is a pointer to a function which is supposed to destroy the data (optional)
*/
void queue_destroy(struct queue *queue, fn_node_data_destroy fn);
/*
* Create a new queue node
*
* fn_node_data_init is a pointer to a function which is supposed to initialize the data and return
* a pointer to it (optional)
* If fn_node_data_init is emitted the node data is the data pointed to by the pointer data argument
*/
struct queue_node *queue_node_init(void *data, fn_node_data_init fn);
/*
* Destroy a queue node
*/
void queue_node_destroy(struct queue_node *node, fn_node_data_destroy fn);
/*
* Add queue node to queue
*/
int queue_enqueue(struct queue *queue, struct queue_node *node);
/*
* Get next node from queue
*/
struct queue_node *queue_dequeue(struct queue *queue);
#endif /* QUEUE_H */