#include<stdio.h>
#include <malloc.h>
#define Max 10
typedef struct Tree
{
int data;
struct Tree *lchild;
struct Tree *rchild;
}Tree;
}*/
void pro(Tree **tree,int *a,int n);
void pro(Tree **tree,int *a,int n)
{
Tree *q=NULL;
Tree *p=NULL;
int k=0;
if(n<Max)
{
if(n==0)
{
(*tree)=(Tree *)(malloc(sizeof(Tree)));
(*tree)->lchild=NULL;
(*tree)->rchild=NULL;
(*tree)->data=a[n];
pro(tree,a,n+1);
}
else
{
q=(Tree *)malloc(sizeof(Tree));
q->lchild=NULL;
q->rchild=NULL;
q->data=a[n];
p=(*tree);
while(p->lchild&&p->data>q->data||p->rchild&&p->data<q->data)
{
if(p->data>q->data)
{
p=p->lchild;
}
else
{
p=p->rchild;
}
}
if(p->data>q->data)
{
p->lchild=q;
}
else
{
p->rchild=q;
}
pro(tree,a,n+1);
}
}
}
int main()
{
int a[Max]={5,6,45,0,47,7,9,1,65,9};
Tree *tree=NULL;
pro(&tree,a,0);
printf("%d",tree->rchild->rchild->data);
}
#include <malloc.h>
#define Max 10
typedef struct Tree
{
int data;
struct Tree *lchild;
struct Tree *rchild;
}Tree;
}*/
void pro(Tree **tree,int *a,int n);
void pro(Tree **tree,int *a,int n)
{
Tree *q=NULL;
Tree *p=NULL;
int k=0;
if(n<Max)
{
if(n==0)
{
(*tree)=(Tree *)(malloc(sizeof(Tree)));
(*tree)->lchild=NULL;
(*tree)->rchild=NULL;
(*tree)->data=a[n];
pro(tree,a,n+1);
}
else
{
q=(Tree *)malloc(sizeof(Tree));
q->lchild=NULL;
q->rchild=NULL;
q->data=a[n];
p=(*tree);
while(p->lchild&&p->data>q->data||p->rchild&&p->data<q->data)
{
if(p->data>q->data)
{
p=p->lchild;
}
else
{
p=p->rchild;
}
}
if(p->data>q->data)
{
p->lchild=q;
}
else
{
p->rchild=q;
}
pro(tree,a,n+1);
}
}
}
int main()
{
int a[Max]={5,6,45,0,47,7,9,1,65,9};
Tree *tree=NULL;
pro(&tree,a,0);
printf("%d",tree->rchild->rchild->data);
}