-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
100 lines (87 loc) · 1.79 KB
/
queue.h
File metadata and controls
100 lines (87 loc) · 1.79 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @defgroup Queue
*
* @brief The module is an Queue.
*
* (Detailed description of the module.)
*
* This is a Queue implemented with a doubly linked list.
*
* It contains different functions to operate the Queue.
*
*
*
* @author Elias Norgren
* @since 2019-11-26
*
* @{
*/
#ifndef QUEUE_H
#define QUEUE_H
#include <stdbool.h>
#include "list.h"
/**
* @brief The type for the queue.
*
* Contains a pointer to a List.
*
*/
typedef struct queue
{
List *list;
int size;
} Queue;
/**
* @brief Create and return an empty queue.
*
* Allocates memory for a Queue and creates a List.
*
* It is the callers responsibility to free the Queue and its elements using
* queue_destroy().
*
* @return Pointer to Queue
*/
Queue *queue_create(void);
/**
* @brief Destroy the queue.
*
* Destroys the List then frees the Queue.
*
*
* @param q pointer to Queue
* @return -
*/
void queue_destroy(Queue *q);
/**
* @brief Add a value to the tail of the queue.
*
* The value is copied to dynamically allocated memory.
* To remove al elements queue_destroy() can be used.
*
* @param q pointer to Queue
* @param value String to enqueue.
* @return -
*/
void queue_enqueue(Queue *q, const unsigned char *value);
/**
* @brief Remove the value at the head of the queue.
*
* The caller is responsible for deallocating the returned pointer.
*
* @param q pointer to Queue
* @return String that was on the removed element.
*/
unsigned char *queue_dequeue(Queue *q);
/**
* @brief Check if the queue is empty.
*
* Looks if the Queue is empty or not.
*
*
*
* @param q pointer to Queue
* @return True if empty. Else false.
*/
bool queue_is_empty(const Queue *q);
int queue_size(const Queue *q);
#endif /* QUEUE_H */