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;
}