6 * bintree_add - Add to tree
8 * Adds a node to a sorted tree. If the new node is already found from
9 * the tree, the existing node is returned and the new node is not
10 * added. If new node is not found, the new one is added and the tree
13 struct bintree *bintree_add(struct bintree *tree, struct bintree *new,
14 struct bintree_ops *ops)
21 ret = ops->compare(tree, new);
24 return bintree_add(tree->left, new, ops);
31 return bintree_add(tree->right, new, ops);
40 * bintree_find - Find a node from a tree.
42 * If node is found, pointer to the node is returned. If no node is
43 * found, null is returned.
45 struct bintree *bintree_find(struct bintree *tree, struct bintree *new,
46 struct bintree_ops *ops)
53 ret = ops->compare(tree, new);
56 return bintree_find(tree->left, new, ops);
63 return bintree_find(tree->right, new, ops);
72 * bintree_walk - walk through a binary tree from left to right
74 * Returns the number of nodes in the tree
76 int bintree_walk(struct bintree *tree, struct bintree_ops *ops)
81 count += bintree_walk(tree->left, ops);
84 ops->callback(tree, ops);
89 count += bintree_walk(tree->right, ops);