代码:
struct BinaryTreeNode
{
int m_val;
BinaryTreeNode* m_pLeft;
BinaryTreeNode* m_pRight;
};
void PrintUpToBottom(BinaryTreeNode* pTree)
{
queue<BinaryTreeNode*> treeQue;
if (pTree == nullptr)
return;
treeQue.push(pTree);
while (!treeQue.empty())
{
BinaryTreeNode* pNode = treeQue.front();
cout << pNode->m_val << " ";
treeQue.pop();
if (pTree->m_pLeft != nullptr)
treeQue.push(pTree->m_pLeft);
if (pTree->m_pRight != nullptr)
treeQue.push(pTree->m_pRight);
}
}