#include<stdio.h>
typedef struct treenode
{
int data;
struct treenode *lchild;
struct treenode *rchild;
}tnode;
void insert(tnode **node,int value)
{
if(!*node)
{
(*node) =(tnode *)malloc(sizeof(tnode));
(*node)->data=value;
(*node)->lchild=NULL;
(*node)->rchild=NULL;
}
else
value>((*node)->data)?insert(&(*node)->rchild,value):insert(&(*node)->lchild,value);
}
tnode * createTree(int arr[],int n)
{
tnode * root=NULL;
int temp;
int i=0;
while(i<n)
{
temp=arr[i++];
insert(&root,temp);
}
return root;
}
void preprintTree(tnode * root)
{
if(root)
{
preprintTree(root->lchild);
printf("%5d",root->data);
preprintTree(root->rchild);
}
}
int main()
{
tnode *root;
int arr[6]={7,1,23,55,9,2};
root=createTree(arr,6);
preprintTree(root);
getch();
return 0;
}
typedef struct treenode
{
int data;
struct treenode *lchild;
struct treenode *rchild;
}tnode;
void insert(tnode **node,int value)
{
if(!*node)
{
(*node) =(tnode *)malloc(sizeof(tnode));
(*node)->data=value;
(*node)->lchild=NULL;
(*node)->rchild=NULL;
}
else
value>((*node)->data)?insert(&(*node)->rchild,value):insert(&(*node)->lchild,value);
}
tnode * createTree(int arr[],int n)
{
tnode * root=NULL;
int temp;
int i=0;
while(i<n)
{
temp=arr[i++];
insert(&root,temp);
}
return root;
}
void preprintTree(tnode * root)
{
if(root)
{
preprintTree(root->lchild);
printf("%5d",root->data);
preprintTree(root->rchild);
}
}
int main()
{
tnode *root;
int arr[6]={7,1,23,55,9,2};
root=createTree(arr,6);
preprintTree(root);
getch();
return 0;
}