You are viewing a single comment's thread. Return to all comments →
if (!m[hd[root->left]]) m[hd[root->left]] = root->left->data;
The idea is that for each node traversed, if that node has a horizontal distance(distance from the centre of the tree) which no other node has had so far, map that horizontal distance to the value of that node.
It goes down the tree and stores the first nodes which are at all the possible distances from the root