How to find the depth of each node in std::map?

五迷三道 提交于 2019-12-11 10:08:31

问题


If I construct, my own binary tree, then I can find the depth of each node. The sample code is as follows

template<class datatype>
void binary_node<datatype>::printNodeWithDepth(int currentNodeDepth)
{
    if ( left )
        left->printNodeWithDepth(currentNodeDepth+1);
    std::cout << value << " and the depth is " << currentNodeDepth << std::endl;
    if ( right)
        right->printNodeWithDepth(currentNodeDepth+1);
}

But wondering, since map is a b-tree, is it possible to write something similar to this for a std::map?


回答1:


std::map is not guaranteed to be a b-tree, it is just guaranteed to have at least as good runtime complexity. To open the door for other potential implementations, the interface does not include functions for inspecting this kind of implementation details. :)



来源:https://stackoverflow.com/questions/3549255/how-to-find-the-depth-of-each-node-in-stdmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!