#include #include "list_int.h" struct list_int { int value; struct list_int * prev; struct list_int * next; }; struct list_int * list_int_new () { struct list_int * this = malloc(sizeof(struct list_int)); if (this) { this->prev = this; this->next = this; } return this; } void list_int_delete (struct list_int * l) { struct list_int * i = l->next; while (i != l) { struct list_int * tmp = i; i = i->next; free(tmp); } free(l); } list_int_iterator list_int_append (struct list_int * l, int v) { return list_int_insert(l, v); } list_int_iterator list_int_insert (list_int_iterator i, int v) { struct list_int * new_l = malloc(sizeof(struct list_int)); if (new_l) { new_l->value = v; new_l->next = i; new_l->prev = i->prev; new_l->prev->next = new_l; new_l->next->prev = new_l; } return new_l; } list_int_iterator list_int_begin (struct list_int * l) { return l->next; } list_int_iterator list_int_end (struct list_int * l) { return l; } int list_int_get (list_int_iterator i) { return i->value; } void list_int_put (list_int_iterator i, int v) { i->value = v; } list_int_iterator list_int_next (list_int_iterator i) { return i->next; } list_int_iterator list_int_prev (list_int_iterator i) { return i->prev; } list_int_iterator list_int_erase (struct list_int * l) { struct list_int * next = l->next; if (l != next) { next->prev = l->prev; next->prev->next = next; free(l); } return next; } void list_int_clear (struct list_int * l) { struct list_int * i = l->next; while (i != l) { struct list_int * tmp = i; i = i->next; free(tmp); } l->next = l; l->prev = l; } int list_int_empty (struct list_int * l) { return l->next == l; }