DListRet dlist_delete(DList* thiz, size_t index) { DListNode* cursor = dlist_get_node(thiz, index, 0); if(cursor != NULL) { if(cursor == thiz->first) { thiz->first = cursor->next; } if(cursor->next != NULL) { cursor->next->prev = cursor->prev; } if(cursor->prev != NULL) { cursor->prev->next = cursor->next; } dlist_node_destroy(cursor); } return DLIST_RET_OK; }
int dlist_delete(DList* thiz, int index) { DListNode* cursor = dlist_get_node(thiz, index, 0); if(cursor != NULL) { if(cursor == thiz->first) thiz->first = cursor->next; if(cursor->next != NULL) cursor->next->prev = cursor->prev; if(cursor->prev != NULL) cursor->prev->next = cursor->next; dlist_node_destroy(cursor); } return 0; }
void dlist_destroy(DList* thiz) { DListNode* iter = thiz->first; DListNode* next = NULL; while(iter != NULL) { next = iter->next; dlist_node_destroy(iter); iter = next; } thiz->first = NULL; free(thiz); return; }