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.