#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; } #ifdef DEBUG int printIntLL (linkedlist *list) { node *index; for (index=list->head; index; index=index->next) printf ("%d\n", *((int *)index->data)); return SUCCESS_LL; } #endif 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; } #define DUMBASSHIT int addHeadSTUPIDSTUPIDSTUPIDSTUPIDLL (linkedlist *list, void *data) { node newnode; if (!list) return NULL_LIST_LL; if (!data) return NULL_DATA_LL; newnode.next = list->head; newnode.data = data; list->head = &newnode; (list->count)++; /* If list was previosuly empty, set tail to only node, newly added */ if (!tail) list->tail = list->head; return SUCCESS_LL; } #endif