I am in the previous blog "C language implementation of the non-cyclic double linked table node deletion (not the lead node)" in detail in the double linked list without the head and tail node to delete a node, the processing process or slightly trouble. Since we've learned to work with a two-linked list using a back-and-tail node, the removal process is very convenient. Code uploaded to Https://github.com/chenyufeng1991/DeleteNodeDoubleLinkedList_HeadList.
The core code is as follows:
Deletes the node int deleteposlist of the POS location (Nodes *phead,node *ptail,int pos) {int i = 1;
Node *pmove;
Pmove = phead->next;
while (Pmove!= ptail) {if (i = = pos) {Pmove->prior->next = pmove->next;
Pmove->next->prior = pmove->prior;
Free (pmove);
Pmove = NULL;
printf ("%s function execution, delete pos=%d location node succeeded \ \", __function__,pos);
return 1;
} i++;
Pmove = pmove->next;
printf ("%s function execution, deletion of node in pos=%d location failed \ \", __function__,pos);
return 0;
//delete the node with a value of x, and if the node is present, remove the int deletevaluelist (node *phead,node *ptail,int x) {node *pmove;
Pmove = phead->next;
while (Pmove!= ptail) {if (pmove->element = = x) {Pmove->prior->next = pmove->next;
Pmove->next->prior = pmove->prior;
Free (pmove);
Pmove = NULL;
printf ("%s function execution, deletion of x=%d node succeeded \ \", __function__,x);
return 1; } Pmove = pmove->next;
printf ("%s function execution, deletion of node with X" failed \ n ", __function__);
return 0; }