Depth
good solution
int depth(Tnode *root) { if (root == NULL) return 0; return MAX(depth(root->left), depth(root->right)) + 1; }
bad solution
int depth2(Tnode *root, int n) { int max; if (root == NULL) return n; n++; max = MAX(depth2(root->left, n), depth2(root->right, n)); return max; }
page revision: 2, last edited: 14 Apr 2010 05:48