C language to realize the linked list of the two-way list (vii) After the end node insertion node __c language

Source: Internet
Author: User
Tags error handling
C language to realize the linked list of the two-way list (vii) After the end of the node insertion point
In the last article, we give the function of removing the head node, this article will give the function of inserting the node after the end node. Pay attention to the processing of the forward pointer in the bidirectional linked list, and learn from the one-way link list.

/*============================================================================== * Operation: Add a new node after the end point * Operation: PHeadNod E is the head pointer of the linked list, listdata for the added node data element * Operation: The node of the data element is Listdata is added to the trailing node, the header node is returned successfully, otherwise null ====================================
==========================================*/mylistnode* Inserttailnode (mylistnode* pHeadNode, MyListData ListData)
    {mylistnode* plistnodetmp = Pheadnode;

    mylistnode* pListNodeTmp1 = NULL;
        Determine if a linked list is entered if (Pheadnode = = NULL) {fprintf (stderr, "There is no list.\n");
    return NULL;
    ///Allocate memory for new node PLISTNODETMP1 = Mallocmeminitnode (PLISTNODETMP1);
        if (pListNodeTmp1 = = NULL) {fprintf (stderr, "The new node ' s memory allocating defeat.\n");
    return NULL;

    } plistnodetmp1->snodedata = Listdata; 
    Move the pointer to the tail node while (plistnodetmp->pnextnodeaddr!= NULL) {plistnodetmp = plistnodetmp->pnextnodeaddr;
   } plistnodetmp->pnextnodeaddr = PLISTNODETMP1; PLISTNODETMP1->PPREVNODEADDR = plistnodetmp;
return pheadnode; }

Highlights points:
(1) The function still calls the Mallocmeminitnode () function to allocate memory, but the data is passed in by the function;
(2) The function still makes error judgment and error handling;
(3) Remember to return the head node.


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.