/* * Free the memory occupied by *l* (the list). * * Note: This frees the memory of all elements in the list represented * by *l*. To free only the _element_ *l*, use cdll_free(). */ void cdll_free_all(struct cdll *l) { if (CDLL_ISEMPTY(l)) { free(l); } else { struct cdll *lnext; while (!(CDLL_ISSINGLT(l))) { lnext = l->next; cdll_free(l); l = lnext; } cdll_free(l); } }
/* * Delete item *i* from cdll *l*. * * Precondition: *i* must be in *l*. */ struct cdll *cdll_delete(struct cdll *l, int i) { struct cdll *lnext; #ifndef NDEBUG struct cdll *ltmp = l; #endif /* DEBUG */ assert(!CDLL_ISEMPTY(l)); if (CDLL_ISSINGLT(l)) { CDLL_SETEMPTY(l); return l; } while (l->item != i) { /* linear search for item */ l = l->next; assert(l != ltmp); } lnext = l->next; cdll_free(l); return lnext; }
void bfs_free_graph(BFS_GRAPH *g) { cdll_free(g->vertex_ll, bfs_free_void_vertex); bh_free(g->vertex_h, NULL); cdll_free(g->edge_ll, bfs_free_void_edge); free(g); }
void bfs_free_vertex(BFS_VERTEX *v) { cdll_free(v->edge_ll, NULL); free(v); }