element_t list_pop_back(list_t l) { ASSERT_LIST(l); ASSERT_LIST_UNDERFLOW(l); return list_erase(l, l->head.next); }
element_t list_pop_front(list_t l) { ASSERT_LIST(l); ASSERT_LIST_UNDERFLOW(l); return list_erase(l, (&l->head)->prev); }
void list_traverse(list_t l, void (*visit)(element_t)) { list_node_t iter; ASSERT_LIST(l); ASSERT_LIST_UNDERFLOW(l); iter = l->front; while (NULL != iter) { visit(iter->e); iter = iter->next; } }
element_t list_remove(list_t l) { element_t e; list_node_t old_node; ASSERT_LIST(l); ASSERT_LIST_UNDERFLOW(l); old_node = l->front; l->front = l->front->next; e = old_node->e; free(old_node); --l->size; return e; }
int list_find(list_t l, element_t e, int (*cmp)(element_t, element_t, int), int elem_sz) { int i = 0; list_node_t iter; ASSERT_LIST(l); ASSERT_LIST_UNDERFLOW(l); iter = l->front; while (NULL != iter) { if (cmp(e, iter->e, elem_sz)) return i; ++i; } return (-1); }
element_t list_pop_front(list_t l) { int i; element_t e; ASSERT_LIST(l); ASSERT_LIST_UNDERFLOW(l); i = l->front; e = l->elements[i].e; l->front = l->elements[i].next; l->elements[i].next = l->free; l->free = i; if (0 == --l->size) l->front = l->rear = l->free = 0; return e; }