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);
}

しかし、不思議に思うのは、マップはBツリーなので、これに似たものをaに書くことは可能std::mapですか?

4

1 に答える 1

7

std::mapが b ツリーであるとは限りません。実行時の複雑さが少なくとも同等であることが保証されているだけです。他の潜在的な実装への扉を開くために、インターフェイスには、この種の実装の詳細を検査するための関数が含まれていません。:)

于 2010-08-23T15:52:19.513 に答える