The C language implements non-Cyclic Use of the head and end nodes to process double-stranded tables (the head node and end node)
I have explained in detail how to delete a node in a double-chain table that does not contain the first and last nodes in my previous blog "delete nodes in non-cyclic double-chain table nodes (do not take the lead node, the processing process is still a little troublesome. Since we learned to use the header and tail nodes to process double-stranded tables, the deletion process is very convenient. Upload the code to https://github.com/chenyufeng1991/deletenodedoublelinkedlist_headlist.
The core code is as follows:
// Delete the 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, node deleted at position pos = % d \ n" ,__ FUNCTION __, pos ); return 1;} I ++; pMove = pMove-> next;} printf ("% s function execution, failed to delete node at position pos = % d \ n ", __function __, pos); return 0;} // delete a Node with the value of x. If the Node exists, 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, the node with the value of x = % d is successfully deleted \ n ",__ FUNCTION __, x); return 1 ;}pmove = pMove-> next ;} printf ("% s FUNCTION execution, failed to delete node with the value of x" ,__ FUNCTION _); return 0 ;}