您的位置:首页 > 其它

二叉树层次遍历

2016-12-07 23:01 197 查看
void printByLevel(Tree t)
{
Tree p;
queue<Tree> q;
q.push(t);
while (!q.empty())
{
p = q.front();
q.pop();
cout << p->val << " ";
if (p->left)
q.push(p->left);
if (p->right)
q.push(p->right);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  二叉树 层次遍历