Delete

Node* Remove(Node *head, int value)
{
    Node *p0, *p1, *temp;
    p1 = head;
 
    while (p1 != NULL && p1->data != value) {
        p0 = p1;
        p1 = p1->next;
    }
 
    if (p1 == NULL) {                      // can't find
        printf("can't find item\n");
    }
    else if (p1 == head) {                // find out at head
        head = head->next;
        free(p1);
    }
    else {                                        // otherwise
        p0->next = p1->next;
        free(p1);
    }
 
    return head;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License