(30 pt) Give Recursive Pseudocode for how one might calculate
the height of a First Child, Next Sibling Tree. To be clear, you
cannot call a regular Binary tree height algorithm – siblings are
at the same “depth”. Assume Nodes defined as:
struct Node{
int val;
Node* child; Node* sibling;
};
struct Node{
int val;
Node* child; Node* sibling;
};
int height(Node* root)
{
if (root == NULL)
return 0;
int maxHeight = 0;
Node* current = root->child;
while (current != NULL)
{
int h =
height(current);
current =
current->sibling;
if(h > maxHeight)
maxHeight = h;
}
return maxHeight + 1;
}
Get Answers For Free
Most questions answered within 1 hours.