C language realization of the chain list of two-way list (vi) Delete header node __c language

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.