小代码二叉树之最大子树和子树判断-成都快上网建站

小代码二叉树之最大子树和子树判断

小代码 二叉树之最大子树 和子树判断

创新互联专注于达茂旗网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供达茂旗营销型网站建设,达茂旗网站制作、达茂旗网页设计、达茂旗网站官网定制、小程序设计服务,打造达茂旗网络公司原创品牌,更为您提供达茂旗网站排名全网营销落地服务。

   #include 
using namespace std;
 typedef struct node
{
    int x;
    node*lc;
    node*rc;
    node(){} 
    node(int xx){x=xx;lc=NULL;rc=NULL;}
}*BiTree;
//int ss[]={1,2,3,0,0,4,0,0,5,6,0,0,7,0,0};int si=0;
//int ss[]={1,2,-3,0,0,-4,0,0,5,-6,0,0,7,0,0};int si=0;//sum=7
int ss[]={1,2,3,0,0,4,0,0,5,-6,0,0,7,0,0};int si=0;//sum=16
BiTree Tb;
BiTree Tc;
 
 void Creat(BiTree &T)
{int d=ss[si++];
  if(d==0) T=NULL;
    else{
        T=new node(d);
        Creat(T->lc);
        Creat(T->rc);
    }
}
void print(node *root,int base)
{//nead creat new style setw(x)
if(root)
{
print(root->rc,base+1);
for(int i=0;ix > 0)
cout<<" "<x<x<lc,base+1);
}
else  return;
}
int sum=0;
bool flag=false;
void maxsum(node *root)
{
if(root==NULL)return;
if(root->lc){maxsum(root->lc);root->x += root->lc->x;}
if(root->rc){maxsum(root->rc);root->x += root->rc->x;}
if(flag)
  {if(root->x > sum )sum=root->x;}
else
  {sum=root->x;flag=true;}
}
  int  sonTree(node *Tb,node *T)
{
 if(Tb)
 {
 if(Tb==T)return 1;
 return  sonTree(Tb->lc,T)+sonTree(Tb->rc,T);
 }
 else
 return 0;
}
 
 
int a[20]={0};
int b[20]={0};
int xx[20]={0};
int xi=0;
//先序遍历
void  DLR(BiTree T)
{
    if(T)
    {
        //cout<x<<' ';
        xx[xi++]=T->x;
        DLR(T->lc);
        DLR(T->rc);
    }
}
 
//中序遍历  
void  LDR(BiTree T)
{
    if(T)
    {
        LDR(T->lc);
        //cout<x<<' ';
        xx[xi++]=T->x;
        LDR(T->rc);
    }
}
//后序遍历 
void   LRD(BiTree T)
{
    if(T)
    {
         LRD(T->lc);
         LRD(T->rc);
       // cout<x<<' ';
        xx[xi++]=T->x;
    }
}
void copy(int *xx,int *ab)
{int i;
for( i=0;i<20;i++)
{ ab[i]=xx[i];
 xx[i]=0;
}
}
void clear(int *array)
{
for(int i=0;i<20;i++)
array[i]=0;
}
 

 
int match(int *a,int *b)
{
int i=0,j=0,r=0;int state=-1;cout<LC->x=TB->LC->x TC->RC->X=TB->RC->X
 *******************/
}
int main()
{
cout<<"-------- test 1---------------"<rc=T;
        //print(Tb,4);
       // cout<lc=Tc;
//print(Tb,4);
//cout<lc)<lc)<rc)<            
            
                                
网站题目:小代码二叉树之最大子树和子树判断
本文网址:http://kswjz.com/article/ghdjhp.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流