这个的程序哪位会帮帮忙~ 急用~
看看这个行吗
#include <stdlib.h>
#define Null 0
struct tree
{
int data;
struct tree *left;
struct tree *right;
};
typedef struct tree treenode;
typedef treenode *btree;
btree insert_btree(btree root,int node)
{
btree new,current,parent;
new=(btree)malloc(sizeof(treenode));
new->data=node;
new->left=Null;
new->right=Null;
if(root==Null)
{
return new;
}
else
{
current=root;
while(current!=Null)
{
parent=current;
if(new->data<current->data)
{
current=current->left;
}
else
{
current=current->right;
}
}
if(new->data<parent->data)
{
parent->left=new;
}
else
{
parent->right=new;
}
return root;
}
}
btree create_btree(int *nodlist,int len)
{
btree root=Null;
int i;
for(i=0;i<len;i++)
{
root=insert_btree(root,nodlist[i]);
}
return root;
}
btree search_btree(btree root,int findnode,int top)
{
btree p1,p2,pointer;
pointer=root;
if(pointer==Null)
{
return Null;
}
else
{
if(pointer->data==findnode)
{
printf("%d<-",pointer->data);
return pointer;
}
else
{
p1=search_btree(root->left,findnode,top);
p2=search_btree(root->right,findnode,top);
if(root->data!=top)
{
if(p1!=Null||p2!=Null)
{
printf("%d<-",root->data);
}
}
else if((p1!=Null|p2!=Null)&&root->data==top)
{
printf("%d",top);
}
if(p1!=Null)
{
return p1;
}
if(p2!=Null)
{
return p2;
}
return Null;
}
}
}
main()
{
int i,index,top;
int nodlist[16]={6,3,1,9,5,7,4,8};
btree root,pointer;
index=8;
root=create_btree(nodlist,index);
top=root->data;
pointer=search_btree(root,8,top);
printf("\n");
getch();
}