C++面试题:从上到下打印二叉树
程序员文章站
2022-06-24 20:40:44
不分行从上到下打印二叉树
思路:层级打印
void PrintFromTopToBottom(BinaryTreeNode* pTreeRoot)
{
if(!pTreeR...
不分行从上到下打印二叉树
思路:层级打印
void PrintFromTopToBottom(BinaryTreeNode* pTreeRoot)
{
if(!pTreeRoot)
return;
std::deque
dequeTreeNode.push_back(pTreeRoot);
while(dequeTreeNode.size())
{
BinaryTreeNode *pNode=dequeTreeNode.front();
dequeTreeNode.pop_front();
printf("%d",pNode->m_nValue);
if(pNode->m_pLeft)
dequeTreeNode.push_back(pNode->m_pLeft);
if(pNode->m_pRight)
dequeTreeNode.push_back(pNode->m_pRight);
}
}
想法:越到这本书的后面,代码就越来越“C++化”,很难受,我只能理解过后抄一遍上来。
上一篇: C语言实现简单的面向对象代码实例
下一篇: Linux下MySQL的安装配置详情