i****m 发帖数: 15 | 1 How to to find the maximum value in a tree? No special
ordering in the tree. May not be balanced.
struct node {
struct node *left;
struct node *right;
int value;};
Thanks. | n******t 发帖数: 4406 | 2 merge.
【在 i****m 的大作中提到】 : How to to find the maximum value in a tree? No special : ordering in the tree. May not be balanced. : struct node { : struct node *left; : struct node *right; : int value;}; : Thanks.
| I**********s 发帖数: 441 | 3 Recursion?
struct node * max_node(struct node * n) {
__return (n == NULL) ? NULL : max(n, max_node(n->left), max_node(n->right));
}
max(a, b, c): returns the biggest node of a, b, c.
A NULL node is considered to be smaller
than a non-NULL node. |
|