forked from anshugupta673/x86_64-decOS-MSC-KIIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.c
69 lines (55 loc) · 1.37 KB
/
lib.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
#include "lib.h"
#include "process.h"
#include "stddef.h"
#include "debug.h"
void append_list_tail(struct HeadList *list, struct List *item)
{
item->next = NULL;
if (is_list_empty(list)) {
list->next = item;
list->tail = item;
}
else {
list->tail->next = item;
list->tail = item;
}
}
struct List* remove_list_head(struct HeadList *list)
{
struct List *item;
if (is_list_empty(list)) {
return NULL;
}
item = list->next;
list->next = item->next;
if (list->next == NULL) {
list->tail = NULL;
}
return item;
}
struct List* remove_list(struct HeadList *list, int wait)
{
struct List *current = list->next;
struct List *prev = (struct List*)list;
struct List *item = NULL;
while (current != NULL) {
if (((struct Process*)current)->wait == wait) {
prev->next = current->next;
item = current;
if (list->next == NULL) {
list->tail = NULL;
}
else if (current->next == NULL) {
list->tail = prev;
}
break;
}
prev = current;
current = current->next;
}
return item;
}
bool is_list_empty(struct HeadList *list)
{
return (list->next == NULL);
}