BST Dump Methods
void BST_BASE<T,P>::Dump (std::ostream& os, int dw, char fill) const
{
if (root_ == nullptr)
return;
Node* fillNode = NewNode(T());
Queue < Node * > Que;
Node * current;
size_t currLayerSize, nextLayerSize, j, k;
Que.Push(root_);
currLayerSize = 1;
k = 1; // 2^LayerNumber
while (currLayerSize > 0)
{
nextLayerSize = 0;
if (dw == 1) os << ' '; // indent picture 1 space
for (j = 0; j < k; ++j)
{
current = Que.Front();
Que.Pop();
if (dw > 1) os << ' '; // indent each column 1 space
if (current == fillNode)
{
os << std::setw(dw) << fill;
}
else
{
os << Node::ColorMap(current->flags_) << std::setw(dw) << current->value_<< ANSI_RESET_ALL;
}
if (current->HasLeftChild())
{
Que.Push(current->lchild_);
++nextLayerSize;
}
else
{
Que.Push(fillNode);
}
if (current->HasRightChild())
{
Que.Push(current->rchild_);
++nextLayerSize;
}
else
{
Que.Push(fillNode);
}
}
os << '\n';
currLayerSize = nextLayerSize;
k *= 2;
} // end while
Que.Clear();
delete fillNode;
}
Node operations to be explained: ColorMap, HasLeftChild, HasRightChild