C-language realization of the linked list of the two-way list (12) to determine whether the list is empty and to get the length of the list __c language

Source: Internet
Author: User
Tags error handling
C language to realize the linked list of the two-way list (12) to determine whether the list is empty and get the length of the linked list
In the last article, we give two functions of setting node data and acquiring node data, this article will give a function to determine whether the linked list is empty and get the length of the linked list, which is a total of two functions.

/*============================================================================== * Operation: Check whether the linked list is empty * before operation: Pheadnode is a linked list After the head pointer * operation: Returns TRUE if the linked list is empty, otherwise returns false ============================================================================== */C_bool Checkmylistempty (mylistnode* pheadnode) {if (Pheadnode = NULL) {printf ("The list is empty.\n")
        ;
    return TRUE;
        else {printf ("The list is no empty.\n");
    return FALSE; }/*============================================================================== * Operation: Get the length of the linked list * before operation: Pheadnode After the head pointer * operation of the linked list: Returns the length of the list ==============================================================================*/int
    Getmylistlen (mylistnode* pheadnode) {mylistnode* plistnodetmp = Pheadnode;

    int ilen = 0;
        Determine if a linked list is entered if (Pheadnode = = NULL) {fprintf (stderr, "There is no list.\n");
    return-1;
        }//Get length while (plistnodetmp!= NULL) {ilen++; PLiStnodetmp = plistnodetmp->pnextnodeaddr;
return Ilen; }

These two functions are simpler, for common error handling and Boolean variables are not too much to say here.
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.