while (q.size()) {
hd = root->hd;
// count function returns 1 if the container
// contains an element whose key is equivalent
// to hd, or returns zero otherwise.
if (m.count(hd) == 0)
m[hd] = root->data;
if (root->left) {
root->left->hd = hd - 1;
q.push(root->left);
}
if (root->right) {
root->right->hd = hd + 1;
q.push(root->right);
}
q.pop();
root = q.front();
}