-
Notifications
You must be signed in to change notification settings - Fork 1
/
q.h
54 lines (47 loc) · 1004 Bytes
/
q.h
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
/*************************************************************
*
Author: Denny Abraham Cheriyan, Adrin Peter Fernandes
Contains functions to initialize, add, delete and rotate
a doubly linked circular queue
*/
#include "TCB.h"
#include <stdio.h>
#include <stdlib.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;
}