简体   繁体   English

如何在std :: map中找到每个节点的深度?

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

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 ? 但是想知道,由于map是b树,是否可以为std::map编写与此类似的内容?

std::map is not guaranteed to be a b-tree, it is just guaranteed to have at least as good runtime complexity. std::map不保证是b树,只保证至少具有良好的运行时复杂度。 To open the door for other potential implementations, the interface does not include functions for inspecting this kind of implementation details. 为了为其他潜在的实现打开大门,该界面不包含用于检查此类实现细节的功能。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM