-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk_Queue.ino
66 lines (61 loc) · 1.02 KB
/
k_Queue.ino
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
/*
#if ((TEST == TEST_QUEUE) || (ADMIN))
#warning Queue
#define QUEUE_LENGTH 4
#define QUEUE_EMPTY -1
struct queue_t
{
uint8_t array[QUEUE_LENGTH];
uint8_t length;
int8_t get;
int8_t set;
};
void initQueue(struct queue_t* queue)
{
queue->length = QUEUE_LENGTH;
queue->get = QUEUE_EMPTY;
queue->set = 0;
}
boolean pushToQueue(struct queue_t* queue, uint8_t value)
{
boolean pushed;
if ((queue->get == queue->set) || (value == 0))
{
pushed = false;
}
else
{
queue->array[queue->set] = value;
if (queue->get < 0)
{
queue->get = queue->set;
}
queue->set = (queue->set + 1) % queue->length;
pushed = true;
}
return pushed;
}
uint8_t popFromQueue(struct queue_t* queue)
{
uint8_t popped;
if (queue->get < 0)
{
popped = 0;
}
else
{
popped = queue->array[queue->get];
queue->get = (queue->get + 1) % queue->length;
if (queue->get == queue->set)
{
queue->get = QUEUE_EMPTY;
}
}
return popped;
}
boolean isQueueEmpty(struct queue_t* queue)
{
return (queue->get == QUEUE_EMPTY);
}
#endif
*/