/*! * \brief Searches the AVL tree and returns the identified node * \param start - node to start the search * \param search_node - searching node * \param fnCompare - function to compare two nodes * \return Address of the find node. */ AVL_TREE_PTR SearchAvlTree(AVL_TREE_PTR start, AVL_TREE_PTR search_node, void * fnCompare) { BINARY_TREE_PTR bt; if ( start == NULL ) return NULL; bt = SearchBinaryTree(&start->bintree, &search_node->bintree, fnCompare); if ( bt ) return STRUCT_ADDRESS_FROM_MEMBER(bt, AVL_TREE, bintree); else return NULL; }
void FindAndReplace(btree* root, const int find, void* newPayLoad) { btree* found = NULL; if(newPayLoad == NULL) return; found = SearchBinaryTree(GetRoot(), find); if(found != NULL) { printf("Found [%s] to replace with [%c]\n", (char *)found->payload, _getLetter(newPayLoad)); SetRoot(DeleteBinaryTreeNode(GetRoot(), _getLetter(found->payload))); SetRoot(InsertRoot(GetRoot(), newPayLoad)); } }