-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
48 lines (42 loc) · 1.02 KB
/
queue.c
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
#include "queue.h"
queue* init_queue(){
queue* re = (queue*)malloc(sizeof(queue)*1);
qelement* root = (qelement*)malloc(sizeof(qelement)*1);
root->processID=-1;
root->startT=-1;
root->finishedT=-1;
root->next=NULL;
root->before=NULL;
re->last=root;
re->first=root;
}
void queue_insert(queue* target,int processID,int startT,int finishedT){
qelement* newel = (qelement*)malloc(sizeof(qelement)*1);
newel->processID=processID;
newel->startT = startT;
newel->finishedT = finishedT;
target->last->next=newel;
newel->before=target->last;
newel->next=NULL;
target->last=newel;
}
void qelement_free(qelement* target){
target->next=NULL;
target->before=NULL;
}
void queue_pop(queue* target){
qelement *tmp = target->first->next;
target->first->next = tmp->next;
if(tmp->next!=NULL)
tmp->next->before = target->first;
qelement_free(tmp);
}
void queue_free(queue* target){
while(queue_first(target)!=NULL){
queue_pop(target);
}
free(target);
}
qelement* queue_first(queue* target){
return target->first->next;
}