[c]代码库
void preorder(Tree T)
//前序
{
if(T != NULL)
{
printf("%c ", T->data);
preorder(T->lchild);
preorder(T->rchild);
}
}
void inorder(Tree T)
//中序
{
if(T != NULL)
{
inorder(T->lchild);
printf("%c ", T->data);
inorder(T->rchild);
}
}
void postorder(Tree T)
//后序
{
if (T != NULL)
{
inorder(T->lchild);
inorder(T->rchild);
printf("%c ", T->data);
}
}
int Max(int a, int b)
{
return a>=b?a:b;
}
int Hight(Tree T)
{
if(T == NULL)
{
return 0;
}
else
{
return Max(Hight(T->lchild), Hight(T->rchild)) + 1;
}
}
int Node(Tree T)
{
if (T == NULL)
{
return 0;
}
else
{
return Node(T->lchild)+Node(T->rchild)+1;
}
}
TreeNode* Moveto(Tree T, char c)
{
if(T != NULL)
{
if(T->data == c)
{
return T;
}
Tree T1 = Moveto(T->lchild,c);
if (T1 != NULL)
{
return T1;
}
Tree T2 = Moveto(T->rchild,c);
if (T2 != NULL)
{
return T2;
}
}
else
{
return NULL;
}
}
int main()
{
Tree T = NULL;
char* pre = "EBADCFHGIKJ";
char* in = "ABCDEFGHIJK";
CreateTree(pre, in ,0, 0, 11, T);
printf("%d\n", Hight(T));
preorder(T);
printf("\n");
inorder(T);
/*int a;
scanf("%d", &a);*/
getchar();
getchar();
return 0;