[题目分析]在二叉树上建立三叉链表若二叉树已用二叉链表表示则可象题那样给每个结点加上指向双亲的指针(根结点的双亲指针为空)至于删除元素值为x的结点以及以x为根的子树与题完全一样请参照题下面给出建立用三叉链表表示的二叉树的算法二叉树按完全二叉树格式输入对非完全二叉树要补上虚结点按完全二叉树双亲和子女存储下标间的关系完成双亲和子女间指针的链接#是输入结束标志$是虚结点标志
BiTree creat()/ /生成三叉链表的二叉树(题目给出PASCAL定义下面的用类C书写)
{BiTree pQ[]root; //Q是二叉树结点指针的一维数组容量足够大
char ch; int rear=; //一维数组最后元素的下标
scanf(&ch);
while(ch!=#)
{p=null;
if(ch!=$){p=(BiTree)malloc(sizeof(nodetp));
p>data=ch; p>lchild=p>rchild=null; }
Q[++rear]=p; //元素或虚结点
if(p){if(rear==) {root=p;root>parent=null; } //根结点
else{Q[rear]>parent=Q[rear/]; /双亲结点和子女结点用指针链上
if (rear%==) Q[rear/]>lchild=Q[rear]; else Q[rear/]>rchild=Q[rear];
}
scanf(%c&ch);
}//while
return(root); }//结束creat
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []