二叉树的层序遍历

1.思路:运用队列,先进先出,上一层出时带入上一层的左右子树,循环实现

void levelorder (BTNode*point)
{
Queue q;
Queueinit(&q);
if(point)
{
Queuepush(&q,point);
}
while(!Queueempty(&q))
{
BTNode*point1=Queuefront(&q);
Queuepop(&q);
printf("%d",point1->data);
if(point1->left)
{
Queuepush(&q,point1->left);
}
if(point1->right)
{
Queuepush(&q,point1->right);
}
}
printf("\n");
Queuedestory(&q);
}

你可能感兴趣的:(数据结构,数据结构)