Binary Tree Rotation.

Solved. Thanks guys.
Last edited on
Why does GetNode create a new node? Isn't it supposed to find a node in your tree? The segfault is there probably because on line 6 (and elsewhere) you access NULL or uninitialized member m_right of a newly created node.
You are right. I shouldn't be calling that at all. Do you have any suggestions as to how I go about finding the node? I am really lost here, any help would be appreciated.
You need a function that generates labels. To generate a label for a node, you need to know the labels of its children. To generate a label for a leaf, you have to know for how many leaves you've already generated labels. You need a function generate_label(Node* node, int* number_of_children_passed) that would return either (generate_label(node-left, ...) + generate_label(node->right, ...))/2 (put the two into variables so that the order of evaluation is defined), if the children exist, or increment *number_of_children_passed and return it multiplied by 10 if they don't. Then just do normal search.
Note that you didn't say how to write labels if only one child exists.
Last edited on
Topic archived. No new replies allowed.