-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
71 lines (54 loc) · 984 Bytes
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "queue.h"
queue * newQueue(proc p)
{
queue * ptr = malloc(sizeof(queue));
queue_node * q = malloc(sizeof(queue_node));
if (!q || !ptr) return NULL;
q->next = NULL;
q->p = p;
ptr->head = q = ptr->tail;
ptr->size = 0;
return ptr;
}
void addOne(queue *q, proc p)
{
queue_node * c = q->head;
while (c != NULL)
c = c->next;
c = malloc(sizeof(queue));
c->p = p;
q->tail = c;
(q->size)++;
}
proc removeProc(queue * q)
{
queue_node * c = q->head;
if (!c)
{
proc pBad = {.burst = 100000};
return pBad;
}
proc p = c->p;
q->head = c->next;
(q->size)--;
free(c);
return p;
}
proc removeShortestBurst(queue * q)
{
queue_node * c = q->head;
proc p, p1, p2;
while (q->size)
{
p1 = removeProc(q);
p2 = removeProc(q);
}
return p;
}
void freeQueue(queue **q)
{
queue * c = *q;
while (c != NULL)
{
}
}