C Implement the head interpolation method and the tail interpolation method to construct the non-cyclic double linked list (not the lead node) __ The end interpolation method

Source: Internet
Author: User

In practical use, the double linked list is more convenient and more flexible than the single linked list. For the basic operation of non cyclic double linked list without the lead node, I have implemented in detail in the article "C language realizes the basic operation of bidirectional non-circular chain list (not lead node)". Today we are going to use two different ways to set up a double linked list with the head interpolation and the trailing interpolation method. Code uploaded to Https://github.com/chenyufeng1991/HeadInsertAndTailInsertDoubleList.

The core code is as follows:

A non-cyclic bidirectional link Table node *tailinsertcreatelist (node *pnode) {node *pinsert, which is not a leading node, is created by the tail interpolation method.
    Node *pmove;
    Pinsert = (node*) malloc (sizeof (Node));
    memset (pinsert, 0, sizeof (Node));
    Pinsert->next = NULL;

    Pinsert->prior = NULL;
    scanf ("%d",& (pinsert->element));

    Pmove = Pnode;
        if (pinsert->element <= 0) {printf ("%s function execution, enter data illegal, create list stop \ n", __function__);
    return NULL;
            while (Pinsert->element > 0) {if (Pnode = = NULL) {pnode = Pinsert;
        Pmove = Pnode;
            }else{pmove->next = Pinsert;
            Pinsert->prior = Pmove;
        Pmove = pmove->next;
        } Pinsert = (node *) malloc (sizeof (node));
        memset (pinsert, 0, sizeof (Node));
        Pinsert->next = NULL;
        Pinsert->prior = NULL;
    scanf ("%d",& (pinsert->element));

    printf ("%s function execution, trailing interpolation to establish the list succeeded \ n", __function__);
return pnode; }//Header create non-cyclic bidirectional linked table node with no lead node*headinsertcreatelist (node *pnode) {node *pinsert;
    Pinsert = (node *) malloc (sizeof (node));

    memset (pinsert, 0, sizeof (Node));
    Pinsert->next = NULL;
    Pinsert->prior = NULL;

    scanf ("%d",& (pinsert->element));
        if (pinsert->element <= 0) {printf ("%s function execution, enter data illegal, create list stop \ n", __function__);
    return NULL;
        while (Pinsert->element > 0) {if (Pnode = = NULL) {pnode = Pinsert;
            }else{pinsert->next = Pnode;
            Pnode->prior = Pinsert;
        Pnode = Pinsert;
        } Pinsert = (node *) malloc (sizeof (node));
        memset (pinsert, 0, sizeof (Node));
        Pinsert->next = NULL;
        Pinsert->prior = NULL;
    scanf ("%d",& (pinsert->element));
    printf ("%s function execution, header build list succeeded \ n", __function__);
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.