思路:
当此结点不为空时,输出此结点并把左右子节点放到队列中,按队列输出并做循环。当队列为空时则打印结束。
void Print_Level(BinaryTreeNode* pRoot)
{
if(pRoot == NULL)
return ;
queue<BinaryTreeNode*>q;
q.push(pRoot);
while(! q.empty())
{
BinaryTreeNode *pCur = q.front();
cout<<pCur->data<<endl;
//因为是层序,这里一定要先左后右,
if(pCur->Left)
q.push(pCur->Left);
if(pCur->Right)
q.push(pCur->Right);
q.pop();
}
}