C language Realization of the chain list of two-way list (vi) Delete header node
The previous article gives a function to insert a node before the head node, and this article will give a function to delete the header node. It is still necessary to note the processing of the forward pointer.
/*==============================================================================
* operation : Delete Header node
* before operation: Ppheadnode is a two-level pointer to the head of a linked list : (*ppheadnode) points to a new header node, the primary node is deleted, and the memory is released,
* If there is only a header node in the list, it will (* Ppheadnode) to NULL, the operation successfully returned
* back true, the operation failed to return false
==================================================== ==========================*/
c_bool deletfirstnode (mylistnode** ppheadnode)
{
mylistnode* plistnodetmp = NULL;
Determine if a list is entered
if ((*ppheadnode) = = NULL)
{
fprintf (stderr, "There is no list.\n");
return FALSE;
}
if ((*ppheadnode)->pnextnodeaddr!= NULL)
{
//Update header node
plistnodetmp = (*ppheadnode)-> pnextnodeaddr;
Plistnodetmp->pprevnodeaddr = NULL;
Free ((*ppheadnode));
(*ppheadnode) = plistnodetmp;
}
else
{
//The original linked list has only the head node, free form free after release
((*ppheadnode));
(*ppheadnode) = NULL;
}
return TRUE;
}
Highlights points:
(1) must pass through the two level pointer, otherwise cannot change the pointer address value;
(2) After the first node deleted to remember to update the head node;
(3) This function uses a Boolean variable of our own definition;
(4) The function is still being handled incorrectly.