二叉排序树的定义是:或者是一棵空树,或者是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值;
题目:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2712/pid/2482
首先在建树上就和普通树上和别的树有些区别
struct tree*creat(struct tree*root,char x)
{
if(root==NULL)
{
root=(struct tree*)malloc(sizeof(struct tree));
root->data=x;
root->l=NULL;
root->r=NULL;
}
else
{
if(x<root->data)
{
root->l=creat(root->l,x);
}
else if(x>root->data)
{
root->r=creat(root->r,x);
}
}
return root;
}
void judge(struct tree*root,struct tree*root)
{
if(root==NULL&&root1==NULL)//如果是空树直接return
return ;
else if(root&&root1)
{
if(root1->data!=root->data)//当不相同的时候直接return
return ;
else//二者相同的时候向下,记录下flag后和len比较
{
flag++;
judge(root->l,root1->l)
judge(root->r,root1->r);
}
}
}
平衡二叉树:
推荐大佬的一篇文章:https://blog.csdn.net/chen_zan_yu_/article/details/84843894
写的真好!我就不付上代码了!
题目链接:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2712/pid/3374