• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

二叉树的子函数好像出了点问题

#include
#include
#include
#include


#define MaxSize 50
typedef int ElemType;
typedef struct node{
ElemType data;
struct node *lchild;
struct node *rchild;
}BTNode,*Bitree;
void InitBiTree(BTNode *&T);
{T=NULL;
}
void CreateBiTree(BTNode *&T,char *str)
{
        BTNode *St[MaxSize],*p=NULL;
        int top=-1,tag,j=0;
        char ch;
        T=NULL;
        ch=str[j];
        while(ch!="\0")
        {
                switch(ch)
                {
                        case'(':top++;St[top]=p;tag=1;break;
                        case')':top--;break;
                        case',':tag=2;break;
                        default:p=(BTNode *)malloc(sizeof(BTNode));
                        p->data=ch;p->lchild=p->rchild=NULL;
                        if(T==NULL)
                        T=p;
                        else
                        {
                                switch(tag)
                                {
                                        case 1:St[top]->lchild=p;break;
                                        case 2:St[top]->rchild=p;break;
                                }
                        }
                }
                j++;
                ch=str[j];
        }
}
BTNode *FindNode(BTNode *T,ElemType x)
{
        BTNode *p;
        if(T==NULL)return NULL;
        else if(T->data==x)return T;
        else
        {
                p=FindNode(T->lchild,x);
                if(p!=NULL)return p;
                else return FindNode(T->rchild,x);
        }
}
BTNode *LchildNode(BTNode *p)
{
        if(p->lchild) return p->lchild;
        else return NULL;
}
BTNode *RchildNode(BTNode *p)
{
        if(p->rchild) return p->rchild;
        else return NULL;
}
int BiTreeDepth(BTNode *T)
{
        int ldep,rdep;
        if(T==NULL)
        return 0;
        if(T->lchild)ldep=BiTreeDepth(T->lchild);
        else
        ldep=0;
        if(T->rchild)rdep=BiTreeDepth(T->rchild);
        else
        rdep=0;
        return(ldep>rdep)?(ldep+1):(rdep+1);
}
void visite(BTNode *T)
{
        if(T==NULL)
        printf("The node does not exist");
        else
        printf("%c",T->data);
}
void PrintBiTree1(BTNode *T)
{
        if(T!=NULL)
        {
                visite(T);
                if(T->lchild!=NULL||T->rchild!=NULL)
                {
                        printf("(");
                        PrintBiTree1(T->lchild);
                        if(T->rchild!=NULL)printf(",");
                        PrintBiTree1(T->rchild);
                        printf(")");
                }
        }
}
void PrintBiTree2(BTNode *T,int level)
{
        if(T!=NULL)
        {
        PrintBiTree2(T->rchild,level+1);
        if(level!=0)
        {
                for(int i=0;ilchild,level+1);
        }
}
void DestoryBiTree(BTNode *&T)
{
        if(T!=NULL)
        {
                DestoryBiTree(T->lchild);
                DestoryBiTree(T->rchild);
                free(T);
        }
}
void main()
{
int a[]={1,2,3,4,5,6};
Bitree T;
InitBiTree(T);
}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!