void LayerOrder(node* root)
{
queue<node*> Q;
root->layer = 1;
Q.push(root);
while(!Q.empty())
{
node* now = Q.front();
Q.pop();
printf("%d ", now->data);
if(now->lchild != NULL)
{
now->lchild->layer = now->layer + 1;
Q.push(now->lchild);
}
if(now->rchild != NULL)
{
now->rchild->layer = now->layer + 1;
Q.push(now->rchild);
}
}
}
二叉树的遍历——BFS
猜你喜欢
转载自blog.csdn.net/tian__si/article/details/113970142
今日推荐
周排行