-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.c
More file actions
56 lines (49 loc) · 1.25 KB
/
Queue.c
File metadata and controls
56 lines (49 loc) · 1.25 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
#include "Queue.h"
void InitQueue(Queue** manager,void* data) {
Queue* newNode = (Queue*)malloc(sizeof(Queue));
newNode->next = newNode;
newNode->data = data;
*manager = newNode;
}
BOOL IsQueueEmpty(Queue* manager) {
return !manager;
}
void InsertQueue(Queue** manager, void* data) {
Queue* newNode = (Queue*)malloc(sizeof(Queue));
newNode->next = (*manager)->next;
newNode->data = data;
(*manager)->next = newNode;
*manager = newNode;
}
void* RemoveQueue(Queue** manager) {
void* res = NULL;
if (*manager) {
Queue* process = (*manager)->next;
Queue* temp = *manager;
if (process != *manager) {
while (process->next != *manager)
process = process->next;
res = process->next->data;
process->next = temp->next;
}
else {
res = process->data;
*manager = NULL;
}
free(temp);
}
return res;
}
short QueueLen(Queue* manager) {
short count=0;
if (manager != NULL) {
Queue* process = manager->next;
count = 1;
while (process != manager)
{
process = process->next;
count++;
}
}
return count;
}