#include
#include
#include
#define MAX_TREE_SIZE 80
typedef struct bit_tree_node
{
unsigned int num;
struct bit_tree_node *lchild,*rchild;
}tree_node,*bit_tree;
unsigned int create_tree(bit_tree *tree)//指针的指针
{
unsigned int num;
printf("please input:\n");
scanf("%d",&num);
if(num == 0)
{
return -1;
}
else
{
*tree =(bit_tree)malloc(sizeof(tree_node));
memset(*tree,0,sizeof(tree_node));
(*tree)->num = num;
printf("please input %d's left child:",(*tree)->num);
create_tree(&((*tree)->lchild));
printf("please input %d's right child:",(*tree)->num);
create_tree(&((*tree)->rchild));
}
return 0;
}
void pre_order(bit_tree tree)//前序遍历
{
if(tree != NULL)
{
printf("%d,",tree->num);
pre_order(tree->lchild);
pre_order(tree->rchild);
}
}
void in_order(bit_tree tree)//中序遍历
{
if(tree != NULL)
{
pre_order(tree->lchild);
printf("%d,",tree->num);
pre_order(tree->rchild);