#include #include #include "linkedlist.h" int initLL (linkedlist *list) { if (!list) return NULL_LIST_LL; list->head = list->tail = NULL; list->count = 0; return SUCCESS_LL; } int addHeadLL (linkedlist *list, void *data) { node *newnode; if (!list) return NULL_LIST_LL; if (!data) return NULL_DATA_LL; newnode = malloc (sizeof(node)); newnode->next = list->head; newnode->data = data; list->head = newnode; (list->count)++; /* If list was previosuly empty, set tail to only node, newly added */ list->tail = list->head; return SUCCESS_LL; } int printLL (const linkedlist *const list, int (*printfn)(const void *, FILE *)) { node *index; for (index=list->head; index; index=index->next) { printfn(index->data, stdout); printf ("\n"); } return SUCCESS_LL; } int removeHeadLL (linkedlist *list, void **data) { node *zombie; if (!list) return NULL_LIST_LL; if (!list->count) return EMPTY_LIST_LL; zombie = list->head; list->head = zombie->next; (list->count)--; *data = zombie->data; free (zombie); if (!list->count) list->tail = NULL; return SUCCESS_LL; } int destroylist (linkedlist *list) { void *notused; if (!list) return NULL_LIST_LL; while (list->count) removeHeadLL(list, ¬used); return SUCCESS_LL; }