|
|
Find a node in a list. -
Parameters:
-
| pStart
|
Node to start the search from. |
| pData
|
Data to search for. |
| bDirection
|
Direction to search in: true is forwards, false is backwards. |
-
Returns:
-
The first node found, or NULL if pData was not found.
-
Remarks:
-
Starting at pStart this function iterates through the list in the direction specified by bDirection comparing all the nodes against pData. If it is found, then the node containing the first occurrence of pData is returned. If pData is not found before the list terminates, NULL is returned.
-
Note:
-
There may be more occurrences of pData in the list, so if a node is returned it is best to continue calling ListFind as shown below. If NULL is passed, NULL will be returned to enable use of the function in this way.
Node *pNode = pList->pHead;
while(pNode = ListFind(pNode, pDataToFind, true)) {
printf("Found %d at %d\n", pDataToFind, pNode);
pNode = pNode->pNext;
} |