#include#includetypedef struct node{ int data; struct node*rchild; struct node *lchild;}btnode;btnode *creat(){ btnode*t; int m; scanf("%d",&m); if(m==0) t=NULL; else { t=(btnode*)malloc(sizeof(btnode)...#include
#include
typedef struct node
{
int data;
struct node*rchild;
struct node *lchild;
}btnode;
btnode *creat()
{
btnode*t;
int m;
scanf("%d",&m);
if(m==0)
t=NULL;
else
{
t=(btnode*)malloc(sizeof(btnode));
t->data=m;
t->lchild=creat();
t->rchild=creat();
}
return t;
}
int getmax(btnode*t,int max)
{
if(t!=NULL)
{ if(maxdata)
max=t->data;
getmax(t->lchild,max);
getmax(t->rchild,max);
}
return max;
}
void main()
{
btnode *p;
int max;
p=creat();
max=p->data;
printf("max=%d\n",getmax(p,max));
}
展开 |
|