0
为什么我的下面的代码进入无限循环?我查了一下refernce- Level Order Traversal of a Binary Tree,我没有发现这个和我的代码有太大的区别。那么究竟是什么问题呢?等级顺序在BST中遍历
void levelorder(struct node *root)
{
queue<struct node*> q;
q.push(root);
while (!q.empty()){
const node * const temp = q.front();
q.pop();
cout<<temp->value << " ";
if(root->left)
q.push(root->left);
if(root->right)
q.push(root->right);
}
}