* @brief Recursively traverses an AVL tree and applies a function to each node * * @param[in] ptree Pointer to the root node of the AVL tree * @param[in] fun Callback function to apply to each node * @param[in,out] arg Additional argument passed to the callback function * * @return int Returns the last result from the callback function (0 if all nodes processed) * * @note This function per
| 235 | * if the callback returns a non-zero value. |
| 236 | */ |
| 237 | int lwp_avl_traversal(struct lwp_avl_struct *ptree, int (*fun)(struct lwp_avl_struct *, void *), void *arg) |
| 238 | { |
| 239 | int ret; |
| 240 | |
| 241 | if (!ptree) |
| 242 | { |
| 243 | return 0; |
| 244 | } |
| 245 | if (ptree->avl_left) |
| 246 | { |
| 247 | ret = lwp_avl_traversal(ptree->avl_left, fun, arg); |
| 248 | if (ret != 0) |
| 249 | { |
| 250 | return ret; |
| 251 | } |
| 252 | } |
| 253 | ret = (*fun)(ptree, arg); |
| 254 | if (ret != 0) |
| 255 | { |
| 256 | return ret; |
| 257 | } |
| 258 | if (ptree->avl_right) |
| 259 | { |
| 260 | ret = lwp_avl_traversal(ptree->avl_right, fun, arg); |
| 261 | if (ret != 0) |
| 262 | { |
| 263 | return ret; |
| 264 | } |
| 265 | } |
| 266 | return ret; |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * @brief Finds the first (leftmost) node in an AVL tree |
no outgoing calls
no test coverage detected