/*-----Find the number of two-degree nodes in the binary tree-----*/
void BNode (Tnode *r)
{
if (r) {
if (r->lchild&&r->rchild)
count++;
BNode (R->lchild);
BNode (R->rchild);
}
}
/*-----Find the number of leaves in the binary tree-----*/
int leaf (tnode *r)
{
if (r==null)
return 0;
Else
if (r->lchild==null && r->rchild==null)
return 1;
Else
Return Leaf (r->lchild) + leaf (r->rchild);
}
/*-----Find the height of the leaf in the binary tree-----*/
int Height (tnode *r)
{
int h1,h2;
if (r==null)
return 0;
else{
H1=height (R->lchild);
H2=height (R->rchild);
if (ABS (H1-H2) >1)
flag=1;
Return 1+ (H1>H2?H1:H2);
}
}
void Main ()
{
Tnode *r;
int height;
Char Post[max],in[max];
printf ("Input inorder and Postorder:/n");
Gets (in);
Gets (post);
Mktree (In,0,strlen (in) -1,post,0,strlen (POST) -1,&r);
printf ("The preorder is as follows:/n");
Preorder (R);
printf ("/nthere is%dletters in the tree./n", Leaf (r));
count=0;
BNode (R);
printf ("/nthere is%d binarynode in the tree./n", count);
flag=0;
Height=height (R);
printf ("/nthe height of the tree is%d/n", height);
if (flag==1)
printf ("/nthis bintree is not a avl!/n");
Else
printf ("/nthis Bintree is an avl!/n");
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.