I was in a previous blog "C language implementation of the non-circular doubly linked list node deletion (do not take the lead node)" in detail on the non-head and tail nodes of the double linked list to delete a node, the process is still a little more trouble. The removal process has been very handy since we learned to use the tail node to process the doubly linked list. The code is uploaded to Https://github.com/chenyufeng1991/DeleteNodeDoubleLinkedList_HeadList.
The core code is as follows:
Delete the POS location node int deleteposlist (node *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 \ n", __function__,pos); return 1; } i++; Pmove = pmove->next; } printf ("%s function execution, deletion of node pos=%d location failed \ n", __function__,pos); return 0;} Delete the node with the value x, and if present, delete 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, delete value for x=%d node succeeded \ n", __function__,x); return 1; } Pmove = pmove->next; } printf ("%s function execution, delete node with value x ' failed \ n", __function__); return 0;}
C language implementation of non-cyclic doubly linked List node deletion (lead node tail junction)