C Implement the head interpolation method and the tail interpolation method to construct the non-cyclic doubly linked list (not the leading node).

Source: Internet
Author: User

In practice, double-linked lists are much more convenient and flexible than single-linked lists. For the basic operation of the non-circular doubly linked list without the lead node, I have detailed implementation in the basic operation of the C language implementation of the two-way non-circular list (no lead node). Today we are going to use two different ways of head interpolation and tail interpolation to create a doubly linked list. The code is uploaded to Https://github.com/chenyufeng1991/HeadInsertAndTailInsertDoubleList.

The core code is as follows:

The tail interpolation method creates a non-circular doubly linked list without a lead node node *tailinsertcreatelist (node *pnode) {node *pinsert;    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, input data illegal, establish linked 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, tail interpolation method to establish link list succeeded \ n", __function__); return pnode;} Head interpolation creates non-circular doubly linked list without a lead node 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, input data illegal, establish linked 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 interpolation method to establish the linked list succeeded \ n", __function__); return pnode;}


C Implement the head interpolation method and the tail interpolation method to construct the non-cyclic doubly linked list (not the leading node).

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.