“ Ctrl AC!一起 AC!”
目录
二叉树的查找算法:
bintree locate(bintree t,datatype x){
bintree p;
if(t==NULL) return NULL;
else {
if(t->data==x) return t;
else{
p=locate(t->lchild,x);
if(p) return p;
else return locate(t->rchild,x);
}
}
}
统计二叉树中结点的个数:
int numofnode(bintree t){
if(t==NULL) return 0;
else return (numofnode(t->lchild)+numofnode(t->rchild)+1);
}
判断两个二叉树是否相等:
int isequal(bintree t1,bintree t2){
int t;
t=0;
if(t1==NULL&&t2==NULL) t=1;
else{
if(t1!=NULL&&t2!=NULL){
if(t1->data==t2->data){
if(isequal(t1->lchild,t2->lchild)){
t=isequal(t1->rchild,t2->rchild);
}
}
}
}
return t;
}
求二叉树的高度:
int depth(bintree t){
int h,lh,rh;
if(t==NULL) h=0;
else{
lh=depth(t->lchild);
rh=depth(t->rchild);
h=max(lh,rh)+1;
}
return h;
}
感谢阅读!!!
“ Ctrl AC!一起 AC!”