q.rear=q.rear+1;
}
}
}
int leafcount(BTree* root)//统计叶子结点个数
{
if(root==NULL) return 0 ;
else
{
if(!root->right&&!root->left) return 1;
else return leafcount(root->left)+leafcount(root->right); }
}
int CountNode (BTree *t) //节点总数
{
int num;
if (t == NULL)
num = 0;
else
num = 1 + CountNode (t->left) + CountNode (t->right); return (num);
}
BTree *copy(BTree *p) // 复制一棵二叉树
{
BTree *temp;
if(p==NULL)
return NULL;
temp=(BTree *)malloc(sizeof(BTree));
temp->data=p->data;
temp->left=copy(p->left);
temp->right=copy(p->right);
return temp;
}
/* 判断两棵二叉树是否相似的递归算法 */
int Similar(BTree *t1, BTree *t2)
{
if(t1==NULL&&t2==NULL) return 1;
if(t1&&t2)
{
if(Similar(t1->left,t2->left)&&Similar(t1->right,t2->right))
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库数据结构_二叉树各种算法实现(4)在线全文阅读。
相关推荐: