0

I want to check to see if a binary tree is perfect. this means that the height of the left and right subtrees of the root are equal and the left and right subtrees of the root are perfectly balanced binary trees. I have written the function but am not sure it is correct. can someone please check my algorithm?

```
template<class elemType>
int check(AVLNode<elemType>* &root)
{
int height = 0;
int lh = 0;
int rh = 0;
if (node == null) {
return height;
}
if (root->llink != null) {
lh = check(root->llink);
}
if (root->rlink != null) {
rh = check(root->rlink);
}
if (root->bfactor != (rh - lh)) {
return 0;
}
if (lh > height) height = lh;
if (rh > height) height = rh;
return ++height;
}
```