独自の二分木を構築すると、各ノードの深さを見つけることができます。サンプルコードは次のとおりです
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
ですか?