完全二叉树(Complete Binary Tree)

Date:2019-03-25 19:36:45

判断一棵树是否为完全二叉树

 1 #include <queue>
 2 using namespace std;
 3 void IsComplete(node* root)
 4 {
 5     queue<node*> q;
 6     q.push(root);
 7     while(!q.empty())
 8     {
 9         root = q.front();
10         q.pop();
11         if(root)
12         {
13             q.push(root->lchild);
14             q.push(root->rchild);
15         }
16         else
17         {
18             while(!q.empty())
19             {
20                 root = q.front();
21                 q.pop();
22                 if(root)
23                 {
24                     printf("No\n");
25                     return ;
26                 }
27             }
28         }
29     }
30     printf("Yes\n");
31 }

 

posted @ 2019-06-03 21:27  林東雨  阅读(455)  评论(0编辑  收藏  举报