-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
60 lines (56 loc) · 1.45 KB
/
Copy pathqueue.c
File metadata and controls
60 lines (56 loc) · 1.45 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
#include "queue.h"
/**
* @brief Initializes the queue.
*
* This function sets up the initial state of the queue.
*
* @param queue Pointer to the queue to be initialized.
*/
void queueInit(QUEUE* queue)
{
queue->front = 0;
queue->rear = 0;
queue->size =0;
}
/**
* @brief Checks if the queue is empty.
*
* This function returns true if the queue has no elements, otherwise false.
*
* @param queue Pointer to the queue to be checked.
* @return true if the queue is empty, false otherwise.
*/
bool queueIsEmpty(QUEUE* queue)
{
return(queue->size == 0);
}
/**
* @brief Pushes an element onto the queue.
*
* This function adds an element to the end of the queue.
* Always push element to queue->rear index.
*
* @param queue Pointer to the queue where the element will be added.
* @param element The element to be added to the queue.
*/
void queuePush(QUEUE* queue, CELL element)
{
queue->data[queue->rear] = element;
queue->rear = (queue->rear + 1) % QUEUE_MAX_SIZE;
queue->size +=1;
}
/**
* @brief Pops an element from the queue.
*
* This function removes and returns the element at the front of the queue.
*
* @param queue Pointer to the queue from which the element will be removed.
* @return The element removed from the front of the queue.
*/
CELL queuePOP(QUEUE* queue)
{
CELL element = queue->data[queue->front];
queue->front = (queue->front + 1) % QUEUE_MAX_SIZE;
queue->size -=1;
return element;
}