void BFS(BinaryTreeNode* pRoot)
{
    if(pRoot==nullptr)
    {
        cout<<"empty binary tree!"<<endl;
        return;
    }
    queue<BinaryTreeNode*>pNode;
    pNode.push(pRoot);
    while(!pNode.empty())
    {
        BinaryTreeNode* pFront=pNode.front();
        pNode.pop();
        cout<<pFront->m_Value<<' ';
        if(pFront->m_pLeft!=nullptr)
            pNode.push(pFront->m_pLeft);
        if(pFront->m_pRight!=nullptr)
            pNode.push(pFront->m_pRight);
    }
    cout<<endl;
}
函数

相关文章: