请实现平衡二叉树的动态插入和调整过程的演示。(100分)

H

haoli

Unregistered / Unconfirmed
GUEST, unregistred user!

你好,请帮帮小弟,我初学数据结构,有一问题急待解决!
问题如下:
请实现平衡二叉树的动态插入和调整过程的演示。
致敬
 
//procedure inorder(p:pointer);
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type
pointer=^node;
node=record
data:real;
left,right:pointer;
end;
var
x:real;
root:pointer;
{$R *.DFM}
procedure add_tree(x:real;
var p:pointer);
begin
if p=nil
then
begin
// 加入一节点
new(p);
with p^do
begin
data:=x;
left:=nil;
right:=nil;
end
end
else
with p^do
if x<data
then
add_tree(x,left) //加入左子树
else
add_tree(x,right)//加入右子树
end;
procedure inorder(p:pointer);

begin
if p<>nil then
begin
inorder(p^.left);
form1.listbox2.items.add(floattostr(p^.data));
inorder(p^.right);
end
end;

procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
listbox1.clear;
i:=0;
root:=nil;
x:=strtofloat(memo1.lines[0]);
listbox1.items.add(floattostr(x));
while x>0do
begin
i:=i+1;
add_tree(x,root);
x:=strtofloat(memo1.lines);
if (x>0) then
listbox1.items.add(floattostr(x));
end;
end;



 

非常感谢buhuilangzi的帮助,但因为小弟是初学
不知能否请给出此问题的算法构思
及基本运算,设计的模块构成,各模块的简要说明,调用关系表。
在此感谢!
 
找本数据结构书看一看不就明白了吗?没问题可以结束了
 
接受答案了.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
顶部