43 lines
991 B
C
43 lines
991 B
C
#include <linkedlist.h>
|
|
#include <stdlib.h>
|
|
|
|
struct ll new_ll() {
|
|
struct ll new;
|
|
new.list = NULL;
|
|
new.head = NULL;
|
|
new.tail = NULL;
|
|
return new;
|
|
}
|
|
|
|
void insert_ll(struct ll *list, const char *key, const char *value) {
|
|
list->list = insert_node(list->tail, key, value);
|
|
list->tail = list->list;
|
|
|
|
if(list->head == NULL) {
|
|
list->head = list->list;
|
|
}
|
|
}
|
|
|
|
void remove_ll(struct ll *list, struct node *link) {
|
|
if(link == list->head && link == list->tail) {
|
|
list->head = NULL;
|
|
list->tail = NULL;
|
|
} else if(link == list->head) {
|
|
list->head = list->head->next;
|
|
list->head->prev = NULL;
|
|
} else if(link == list->tail) {
|
|
list->tail = list->tail->prev;
|
|
list->tail->next = NULL;
|
|
} else {
|
|
link->prev->next = link->next;
|
|
link->next->prev = link->prev;
|
|
}
|
|
|
|
link->next = NULL;
|
|
link->prev = NULL;
|
|
link->key = NULL;
|
|
link->value = NULL;
|
|
free(link);
|
|
link = NULL;
|
|
}
|