-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions_queue.c
75 lines (64 loc) · 1.52 KB
/
functions_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
72
73
74
75
/** @file */
#include <stddef.h>
#include <stdlib.h>
#include <f_queue.h>
void add_function(struct f_queue **head, struct f_queue **tail, const short f_type, const int arg1, const int arg2)
{
struct f_queue *node = malloc(sizeof(struct f_queue));
node->f_type = f_type;
node->f_args[0] = arg1;
node->f_args[1] = arg2;
node->prev = NULL;
if(*head == NULL) {
*tail = node;
node->next = NULL;
}
else {
node->next = *head;
(*head)->prev = node;
}
*head = node;
}
void free_all_but_tail(struct f_queue **head)
{
while ((*head)->next != NULL) {
struct f_queue *to_be_deleted = *head;
*head = to_be_deleted->next;
(*head)->prev = NULL;
free(to_be_deleted);
}
}
void free_tail(struct f_queue **head, struct f_queue **tail)
{
struct f_queue *to_be_deleted = *tail;
*head = NULL;
*tail = NULL;
free(to_be_deleted);
}
void free_recording(struct f_queue **head, struct f_queue **tail)
{
free_all_but_tail(head);
free_tail(head, tail);
}
void make_queue_cyclic(struct f_queue *head, struct f_queue *tail)
{
tail->next = head;
head->prev = tail;
}
void unmake_queue_cyclic(struct f_queue *head, struct f_queue *tail)
{
tail->next = NULL;
head->prev = NULL;
}
void trim_head(struct f_queue **head)
{
struct f_queue *to_be_deleted = *head;
*head = to_be_deleted->next;
free((*head)->prev);
(*head)->prev = NULL;
}
void trim_list(struct f_queue **head)
{
trim_head(head);
trim_head(head);
}