void PrintTreeNode(const TreeNode* pNode)
{
if (pNode != nullptr)
{
printf("value of this node is: %d.\n", pNode->m_nValue);
printf("its children is as the following:\n");
std::vector<TreeNode*>::const_iterator i = pNode->m_vChildren.begin();
while (i < pNode->m_vChildren.end())
{
if (*i != nullptr)
{
printf("%d\t", (*i)->m_nValue);
++i; //此句不加会导致程序进入死循环
}
printf("%d\t", (*i)->m_nValue);
}
printf("\n");
}
else
{
printf("this node is nullptr.\n");
}
printf("\n");
}
在PrintTreeNode(const TreeNode* pNode)函数中,遗漏了一句++i;,如下: