Binary Tree Rotation.

Apr 22, 2012 at 5:25am
Solved. Thanks guys.
Last edited on Apr 22, 2012 at 6:43pm
Apr 22, 2012 at 5:53am
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.
Apr 22, 2012 at 6:05am
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.
Apr 22, 2012 at 12:15pm
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 Apr 22, 2012 at 12:17pm
Topic archived. No new replies allowed.