如何在std :: map中找到每个节点的深度? [英] How to find the depth of each node in std::map?

查看:105
本文介绍了如何在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);
}

但是想知道,由于map是b树,是否可以为std::map编写与此类似的内容?

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

推荐答案

std::map不能保证是b树,只能保证至少具有良好的运行时复杂度.为了为其他可能的实现方式打开方便之门,该界面不包含用于检查此类实现方式详细信息的功能. :)

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. :)

这篇关于如何在std :: map中找到每个节点的深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆