二叉树层次遍历

二叉树的层次遍历,也就是广度优先遍历。代码如下:

 1 void HierarchyBiTree(BiTree *Root)
 2 {
 3     LinkQueue *Q; 
 4 
 5     InitQueue(Q); 
 6 
 7     if (Root == NULL) return ; 
 8     
 9     BiNode *p = Root; 
10     EnQueue(Q, p);
11 
12     while (!QueueEmpty(Q)) 
13     {                
14         DeQueue(Q, p); 
15         Visit(p->data);
16 
17         if (p->lchild)
18             EnQueue(Q, p->lchild); 
19         if (p->rchild)
20             EnQueue(Q, p->rchild); 
21     }
22 
23     DestroyQueue(Q);              
24     return ;
25 }
原文地址:https://www.cnblogs.com/yyxayz/p/4118728.html