-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathq.cpp
More file actions
41 lines (37 loc) · 903 Bytes
/
q.cpp
File metadata and controls
41 lines (37 loc) · 903 Bytes
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
#include "include/internal/q.h"
void InitQ(TCB_t **head) {
*head = 0;
}
void AddQ(TCB_t **head, TCB_t *item) {
if (*head == 0) {
//When the head pointer is null
*head = item;
(*head)->next = *head;
(*head)->prev = *head;
} else {
//When there is one or more nodes
(*head)->prev->next = item;
item->prev = (*head)->prev;
(*head)->prev = item;
item->next = *head;
}
}
TCB_t * DelQ(TCB_t **head) {
if ((*head) == 0)
return 0;
TCB_t *temp = *head;
if ((*head)->next == *head) {
//When there is one node
*head = 0;
} else {
//When there are two or more nodes
*head = (*head)->next;
temp->prev->next = *head;
(*head)->prev = temp->prev;
}
return temp;
}
void RotateQ(TCB_t **head) {
if (*head != 0)
(*head) = (*head)->next;
}