void PreOrderPrint(BiTree p); //先序遍历输出结点(递归)
void InOrderPrint(BiTree p); //中序遍历输出结点(递归)
void PostOrderPrint(BiTree p); //后序遍历输出结点(递归)
BiTree BiTreeByPreInd(ElemType pre[], ElemType ind[], int preLeft, int preRight, int indLeft, int indRight);//根据先序和中序序列生成一棵二叉树
BiTree BiTreeByPostInd(ElemType post[], ElemType ind[], int postLeft, int postRight, int indLeft, int indRight);//根据后序和中序序列生成一棵二叉树
BiTree BiTreeByPreInd(ElemType pre[], ElemType ind[], int preLeft, int preRight, int indLeft, int indRight)//根据先序和中序序列生成一棵二叉树
{
BiTree head = NULL;
int root, right;
if (preLeft <= preRight)
{
head = (BiTree)malloc(sizeof(BiTreeNode));
if (!head)
{
printf("Out of space!");
exit (1);
}
head->data = pre[preLeft];
root = indLeft;
while (ind[root] != pre[preLeft]) //在中序序列中查找根结点
root++;
BiTree BiTreeByPostInd(ElemType post[], ElemType ind[], int postLeft, int postRight, int indLeft, int indRight)//根据后序和中序序列生成一棵二叉树
{
BiTree head = NULL;
int root, left;
if (postLeft <= postRight)
{
head = (BiTree)malloc(sizeof(BiTreeNode));
if (!head)
{
printf("Out of space!");
exit (1);
}
head->data = post[postRight];
root = indLeft;
while (ind[root] != post[postRight]) //在中序序列中查找根结点
root++;