#include
#include
/*
*/
typedef struct node
{
int data;
struct node*left;
struct node*right;
}BTnode;
BTnode*CreateTree(int a[],int n){
BTnode*root,*c,*p,*pa;
int i;
root=(BTnode*)malloc(sizeof(BTnode));
root->data=a[0];
root->left=root->right=NULL;//
for(i=1;idata=a[i];
p->left=p->right=NULL;
c=root; // C
while(c)
{ // p
pa=c; //pa p
if(c->data>p->data)
c=c->left;
else
c=c->right;
}
if(pa->data>p->data) //p
pa->left=p;
else
pa->right=p;
}
return root;
}
BTnode * Query(BTnode *root,BTnode *parent,BTnode *p,int key)
{
if(!root)
p = parent;
return NULL;
if(root->data == key)
p=root;
return root;
if(key data )
return Query(root->left,root,p,key);
if(key >root->data )
return Query(root->right,root,p,key);
}
void Forder(BTnode*root)
{
if(root){
printf("%d",root->data);
printf("
");
Forder(root->left);
Forder(root->right);
}
}
void Inorder(BTnode*root)
{
if(root){
Inorder(root->left);
printf("%3d",root->data);
printf("
");
Inorder(root->right);
}
}
void Porder(BTnode*root)
{
if(root){
Porder(root->left);
Porder(root->right);
printf("%6d",root->data);
printf("
");
}
}
int main(void)
{
BTnode*root;
int *a;
int n;
int i;
printf(" n=");
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
printf(" a[]=");
for(i=0;idata);
}