二叉排序树的实现

来源:百度知道 编辑:UC知道 时间:2024/05/06 14:37:36
请问哪位大哥有数据结构的”二叉排序树的实现”的C++的源程序呀!
具体要求如下(最好是有中文解释的呀):
用顺序和二叉链表作存储结构
1.以回车('\n')为输入结束标志,输入数列L,生成一棵二叉排序树T;
2.对二叉排序树T作中序遍历,输出结果;
3.输入元素x,查找二叉排序树T,若存在含x的结点,则删除该结点,并作中序遍历(执行操作;否则输出信息“无x”;
谢谢了了呀!兄弟我急用呀!

Program p6_6(Input, Output);
Type tree=^node;
node=Record
data:Integer;
lchild,rchild:tree;
End;
Var bt:tree;
n:Integer;

Procedure creat_order_tree(Var btx:tree;nx:Integer);
Var p,s,f:tree;
flag:Boolean;
Begin
New(s);
s^.data:=nx;
s^.lchild:=Nil;
s^.rchild:=Nil;
flag:=True;
p:=btx;
While (p<>Nil) And flag Do
Begin
f:=p;
If s^.data=p^.data Then flag:=False
else If s^.data<p^.data Then p:=p^.lchild
else p:=p^.rchild;
End;
If flag Then Begin
If btx=Nil Then btx:=s;
If s^.data<f^.data Then f^.lchild:=s;
If s^.data>f^.data Then f^.rchild:=s;
End;
End;

Procedure inorder_print(btx:tree);
Beg