二叉树的层次遍历
void levelTraverse(BiTree pRoot){
if(pRoot==NULL)
return;
queue<BiTree>q;
q.push(pRoot);
BiTree head=pRoot,tail=pRoot;
int level=1;
while(!q.empty()){
head=q.front();
if(head->lchild!=NULL){
q.push(head->lchild);
}
if(head->rchild!=NULL){
q.push(head->rchild);
}
if(head==tail){
level++;
tail=q.back();
}
cout<<head->data<<" ";
q.pop();
}
}