建一二叉搜树 ( 积分: 0 )

  • 主题发起人 summer_core99
  • 开始时间
S

summer_core99

Unregistered / Unconfirmed
GUEST, unregistred user!
建一二叉搜树,把数组的内容往二叉树中放(大的放左,小的放右)然后用中序遍历(非递归),完了就把二叉树释放,用C语言写,或delphi
 
建一二叉搜树,把数组的内容往二叉树中放(大的放左,小的放右)然后用中序遍历(非递归),完了就把二叉树释放,用C语言写,或delphi
 
求求各程林高手,露上一手~
 
program Project1;
{$APPTYPE CONSOLE}
type
PNode = ^TNode;
TNode = record
Value: Integer;
LeftChild, RightChild: PNode
end;

var
Tree: PNode;
a: array [1..10] of Integer;
i: Integer;
procedure Insert(var Root: PNode;
Value: Integer);
begin
if Root=nil then
begin
New(Root);
Root.Value:=Value;
Root.LeftChild:=nil;
Root.RightChild:=nil
end
else
if Value<Root.Value then
Insert(Root.LeftChild, Value)
else
Insert(Root.RightChild, Value)
end;

procedure Print(Root: PNode);
begin
if Root=nil then
Exit;
Print(Root^.LeftChild);
Write(Root^.Value, ' ');
Print(Root^.RightChild)
end;

begin
Randomize;
Tree:=nil;
for i:=1 to 10do
a:=Random(100);
for i:=1 to 10do
Insert(Tree, a);
Print(Tree);
ReadLn
end.
 

Similar threads

S
回复
0
查看
959
SUNSTONE的Delphi笔记
S
S
回复
0
查看
779
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
563
import
I
顶部