I am having trouble with this, it works... kind of except for deleting the head and the node it deletes prints as 0 !!
can anyone tell me what im doing wrong please!Code:list_t *delete_value (list_t *list, int value) { node_t *ptr, *prev, *tmp; ptr = list->head; while (ptr!=NULL) { if (list->head->data==value) { tmp=list->head; if (list->head->next!=NULL) { list->head = list->head->next; free(tmp); ptr = list->head; prev = ptr; } else { list->head = list->foot = NULL; free(tmp); } } prev = ptr; if (ptr->data==value) { tmp = prev; prev = ptr->next; free(tmp); ptr = prev; } if (ptr->data==value && ptr->next==NULL) { tmp = prev; prev = NULL; free(tmp); ptr = prev; } ptr = ptr->next; } return list; }



LinkBack URL
About LinkBacks


