I am trying to find the height of the BST, but unfortunately I get the number of elements in the BST
Input: 1 2 3
Output: height = 3
Input : 1 2 3 4 5
Output: height = 5
Code:int height(node_ptr tree) { int l = 0; int r = 0; if(tree == NULL) { return 0; } { l = height(tree->left); r = height(tree->right); if( l > r || l == r) { return (l + 1); } else { return (r + 1); } } }
Can you point my mistake and help me to fix it please?