C language implementation of non-cyclic double linked table node deletion (not the lead node)

Source: Internet
Author: User
Tags int size

Non-cyclic double linked lists without the leading nodes are troublesome when deleting nodes, because the prior and next two pointers are maintained. Both the first node and the last node should be considered separately, while the number of nodes should be considered 1. The deletion is divided into the following two categories:

(1) Delete the node of POS position;

(2) Determine if x is in the linked list, if it exists then delete;

Code uploaded to Https://github.com/chenyufeng1991/DeleteNodeDoubleList.

The core code is as follows:

Delete node nodes *deleteposlist of POS Locations {//Note that the first node and the last node int i = 1 need to be considered separately;
    int size = Sizelist (Pnode);
    Node *pmove;

    Pmove = Pnode;
        List is null if (Pnode = null) {printf ("%s function execution, list NULL, delete node failed \ \", __function__);
    return pnode;
        //List only one node, delete the first node if (pos = = 1 && size = = 1) {free (pnode);
        Pnode = NULL;
        printf ("%s function execution, delete pos=%d location node succeeded \ \", __function__,pos);
    return NULL;
        }//Linked list node is greater than 1, delete the first node if (pos = = 1) {Pnode = pnode->next;
        Pnode->prior = NULL;
        Free (pmove);
        Pmove = NULL;
        printf ("%s function execution, delete pos=%d location node succeeded \ \", __function__,pos);
    return pnode; while (Pmove!= NULL) {if (i = = pos && pos!= size) {Pmove->prior->next = Pmov
            e->next;
            Pmove->next->prior = pmove->prior;
            Free (pmove);

            Pmove->next = NULL; printf ("%s function execution, deleting P"os=%d location node succeeded \ n ", __function__,pos);
        return pnode;
            } if (i = = pos && pos = size) {Pmove->prior->next = NULL;
            Free (pmove);
            Pmove = NULL;
            printf ("%s function execution, delete pos=%d location node succeeded \ \", __function__,pos);
        return pnode;
        } i++;
    Pmove = pmove->next;
    printf ("%s function execution, deletion of node in pos=%d location failed \ \", __function__,pos);
return pnode;
    }//To determine if X is in the linked list, delete the node *deletevaluelist (node *pnode,int x) {node *pmove;
    Pmove = Pnode;

    int size = Sizelist (Pnode);
        The original list is null if (Pnode = null) {printf ("%s function execution, original linked list is empty, delete node failed \ \", __function__);
    return NULL;
        //delete is the first node, and the linked list length is 1 if (pnode->element = x && size = = 1) {free (pnode);
        Pnode = NULL;
        printf ("%s function execution, deletion of%d node succeeded \ \", __function__,x);
    return pnode;
//Consider deleting the first node separately, and the list length is greater than 1 if (pnode->element = x) {Pnode = pnode->next;        Free (pnode->prior);

        Pnode->prior = NULL;
        printf ("%s function execution, deletion of%d node succeeded \ \", __function__,x);
    return pnode; } while (Pmove!= null) {//the node to be deleted is not the last if (pmove->element = = x && pmove->next!= null
            ) {Pmove->prior->next = pmove->next;
            Pmove->next->prior = pmove->prior;
            Free (pmove);
            Pmove = NULL;
            printf ("%s function execution, deletion of%d node succeeded \ \", __function__,x);
        return pnode; //To be deleted is the last node if (pmove->element = = x && pmove->next = NULL) {PMOVE->PR
            Ior->next = NULL;
            Free (pmove);
            Pmove = NULL;
            printf ("%s function execution, deletion of%d node succeeded \ \", __function__,x);
        return pnode;
    } Pmove = pmove->next;
    printf ("%s function execution, deletion value%d node failed \ \ __function__,x");
return pnode;
 }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.