1

如果我构建自己的二叉树,那么我可以找到每个节点的深度。示例代码如下

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-tree,是否可以为 a 写一些类似的东西std::map

4

1 回答 1

7

std::map不保证是 b-tree,只是保证至少有同样好的运行时复杂度。为了打开其他潜在实现的大门,该接口不包括检查此类实现细节的功能。:)

于 2010-08-23T15:52:19.513 回答