![]() Tdelete() frees the memory required for the node in the tree. Take a pointer to a variable which points to the root. NOTES top twalk() takes a pointer to the root, while the other functions │ twalk_r() │ Thread safety │ MT-Safe race:root │ │ twalk() │ Thread safety │ MT-Safe race:root │ │ tsearch(), tfind(), │ Thread safety │ MT-Safe race:rootp │ Tsearch(), tfind(), and tdelete() also return NULL if rootp wasįor an explanation of the terms used in this section, see Node, tdelete() returns a dangling pointer that must not be Tdelete() returns a pointer to the parent of the node deleted, or Key, the item whose node is returned is unspecified. If there are multiple items that match the tfind() returns a pointer to the node, or NULL if The newly added node, or NULL if there was insufficient memory toĪdd the item. RETURN VALUE top tsearch() returns a pointer to a matching node in the tree, or to Work is necessary, free_node must point to a function doing The data is passed as the argument to the function. For the data inĮach tree node the function free_node is called. Resources allocated by the tsearch() function. Tdestroy() removes the whole tree pointed to by root, freeing all This pointer canīe used to pass information to and from the callback function inĪ thread-safe fashion, without resorting to global variables. Invocation of the action callback, unchanged. Twalk_r() is similar to twalk(), but instead of the depthĪrgument, the closure argument pointer is passed to each Thus, the choice of name postorder is rather Preorder, inorder, and postorder: before visiting the children,Īfter the first and before the second, and after visiting theĬhildren. (More commonly, preorder, postorder, and endorder are known as ) The third argument is the depth of the node the ![]() Third visit to the internal node, or the value leaf if this is Or endorder depending on whether this is the first, second, or Is an integer which takes one of the values preorder, postorder, The structure pointed to by this argument. Pointer to a pointer-to-pointer-to-element in order to access theĮlement stored within the node. Of the node is unspecified, but it is possible to cast the The firstĪrgument is a pointer to the node being visited. Is visited (that is, three times for an internal node, and onceįor a leaf). twalk() calls the user function action each time a node That node is not the root, then only part of the tree will be root points to the starting node for the traversal. Twalk() performs depth-first, left-to-right traversal of a binary Tfind() is like tsearch(), except that if the item is not found, Pointer to a pointer to the data item.) If the item is notįound, then tsearch() adds it, and returns a pointer to the In the tree, then tsearch() returns a pointer to theĬorresponding tree node. That rootp points to should be set to NULL. rootp points to a variable which points to Is less than, equal to, or greater than the second. Negative, zero, or positive, depending on whether the first item (The calling program must store theĪctual data.) compar points to a comparison routine, which takes Theįirst field in each node of the tree is a pointer to theĬorresponding data item. They are generalized from Knuth (6.2.2) Algorithm T. #include void twalk_r(const void * root, void (* action )(const void * nodep, VISIT which, void * closure ), void * closure ) void tdestroy(void * root, void (* free_node )(void * nodep )) DESCRIPTION top tsearch(), tfind(), twalk(), and tdelete() manage a binary search SYNOPSIS top #include typedef enum VISIT void *tsearch(const void * key, void ** rootp, int (* compar )(const void *, const void *)) void *tfind(const void * key, void *const * rootp, int (* compar )(const void *, const void *)) void *tdelete(const void *restrict key, void **restrict rootp, int (* compar )(const void *, const void *)) void twalk(const void * root, void (* action )(const void * nodep, VISIT which, int depth )) #define _GNU_SOURCE /* See feature_test_macros(7) */ ![]() ![]() Tsearch, tfind, tdelete, twalk, twalk_r, tdestroy - manage a Tsearch(3) Library Functions Manual tsearch(3) NAME top ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |