This repository was archived by the owner on Oct 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.h
More file actions
49 lines (41 loc) · 1.26 KB
/
queue.h
File metadata and controls
49 lines (41 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
/// Queue structure
struct array_queue {
int* data; // array storing the desired data
int first; // index of the queue's first element in the buffer
int size; // amount of data points stored
int capacity; // maximum amount of data points permitted
};
typedef struct array_queue queue;
/**
* @brief Allocates memory and starts an empty queue.
*
* @param capacity the maximum number of data points the queue will be allowed to store in its array
* @return The address of the queue created.
*/
queue* queate(int capacity);
/**
* @brief Adds a new data point in the queue.
* If the buffer is full, the old data is not overwritten.
*
* @param q queue receiving data
* @param key the data being stored
* @return 1, on success. 0, on failure.
*/
int enqueue(queue* q, int key);
/**
* @brief Deletes the first data point in the queue by invalidating
* its position with the `first` and `size` fields.
*
* @return The address of value removed. If que queue is null or empty, it returns NULL.
*/
int* dequeue(queue* q);
/**
* @brief Releases a queue and its array.
*/
void free_queue(queue* q);
/**
* @brief Prints all the data points in queue sequentially and separated by spaces.
*
* @param q queue being printed
*/
void printq(queue* q);