This commit is contained in:
Krzosa Karol
2022-05-07 15:48:53 +02:00
parent d3ede16bab
commit 042127239e
11 changed files with 629 additions and 266 deletions

55
dllqueue.c Normal file
View File

@@ -0,0 +1,55 @@
function void
push(Type *l, Type *node){
if(l->first == 0){
l->first = l->last = node;
node->prev = 0;
node->next = 0;
}
else{
l->last->next = node;
node->prev = l->last;
node->next = 0;
l->last = node;
}
node->parent = l;
}
function void
push_front(Type *l, Type *node){
if(l->first == 0){
l->first = l->last = node;
node->prev = 0;
node->next = 0;
}
else{
node->next = l->first;
l->first->prev = node;
node->prev = 0;
l->first = node;
}
node->parent = l;
}
function void
remove(Type *l, Type *node){
if(l->first == l->last){
assert(node == l->last);
l->first = l->last = 0;
}
else if(l->last == node){
l->last = l->last->prev;
l->last->next = 0;
}
else if(l->first == node){
l->first = l->first->next;
l->first->prev = 0;
}
else{
node->prev->next = node->next;
node->next->prev = node->prev;
}
node->parent = 0;
node->prev = 0;
node->next = 0;
}