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).