#includestdio.h #includestdlib.h struct ele { int value; ele* left; ele* right; }; void build(ele *p) { int n; scanf("%d",n); if(n==0) p=NULL; else { p=(ele*)malloc(sizeof(ele)); p-value=n; build(p-left); build(p-right); } } void search(ele
#include<stdio.h>
#include<stdlib.h>
struct ele
{
int value;
ele* left;
ele* right;
};
void build(ele *&p)
{
int n;
scanf("%d",&n);
if(n==0)
p=NULL;
else
{
p=(ele*)malloc(sizeof(ele));
p->value=n;
build(p->left);
build(p->right);
}
}
void search(ele*&p)
{
if(p==NULL)
return;
else
{
printf("%d
",p->value);
search(p->left);
search(p->right);
}
}
int sum(ele *&p)
{
if(p==NULL)
return 0;
else
{
int m,n;
m=sum(p->left);
n=sum(p->right);
if(m>n)
return m+1;
return n+1;
}
}
int countsum(ele*&p)
{
if(p==NULL)
return 0;
else
return countsum(p->left)+countsum(p->right)+1;
}
int main()
{
ele *p;
build(p);
search(p);
printf("%d\n",sum(p));
printf("%d\n",countsum(p));
return 0;
}