题目:从上往下打印出二叉树的每个结点,同一层的结点按照从左到右的顺序打印。
二叉树结点的定义如下:
代码如下:
void PrintBinaryTree(Node* head)
{
Queue<Node*> qu;
qu.push(head);
while(!qu.empty())
{
Node* temp = qu.top();
print qu.data;
qu.pop();
if(qu->left != NULL)
{
qu.push(qu->left);
}
if(qu->right != NULL)
{
qu.push(qu->right)
}
}
}