Дерево у меня строится, строится график эффективности алгоритма, а вот с выводом дерева трудности! Может кто-нибудь подскажет, как правильно его реализовать с помощью TTreeView... Помогите, пожалуста, вот текст программы и в архиве сама программа.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, TeEngine, Series, ExtCtrls, TeeProcs, Chart;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Panel2: TPanel;
Chart1: TChart;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
Series1: TLineSeries;
Series2: TLineSeries;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
tTree = ^tNode;
tNode = record
data : string[5];
left : tTree;
right : tTree;
end;
const
nabsmax = 999;
bd = 1000000;
var
Form1: TForm1;
A : array [1..nabsmax] of string[5];
B : array [0..nabsmax] of string[5];
P : array [1..nabsmax] of integer;
Q : array [0..nabsmax] of integer;
W,C : array [0..nabsmax,0..nabsmax] of integer;
R : array [0..nabsmax,0..nabsmax] of string[5];
implementation
{$R *.dfm}
procedure BuildTree(var root : ttree; y,z : integer);
var
c : integer;
d : string[5];
begin
new(root);
d := R[y,z];
root^.data := d;
root^.left := nil;
root^.right := nil;
delete(d,1,1);
c := StrToInt(d);
if y <> z
then
begin
BuildTree(root^.left,y,c-1);
BuildTree(root^.right,c,z);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,m,k,x,Cij,n,nmax,rand,count : integer;
tree : ttree;
begin
nmax := StrToInt(self.LabeledEdit1.Text); // считали количество проходок
rand := StrToInt(self.LabeledEdit2.Text); // считали рандом для частот
randomize;
for n := 1 to nmax do // запускаем цикл для изменяющегося количества элементов
begin
Fillchar(W,sizeof(W),0); // обнуляем
Fillchar(C,sizeof©,0); // все
Fillchar(R,sizeof®,' '); // исходные
Fillchar(A,sizeof(A),' '); // массивы
Fillchar(B,sizeof(B),' '); // данных
for i := 1 to n do // забиваем массив A
A[i] := 'a' + IntToStr(i);
for i := 0 to n do // забиваем массив B
B[i] := 'b' + IntToStr(i);
for i := 1 to n do
P[i] := random(rand) + 1;
for i := 0 to n do
Q[i] := random(rand) +1;
count := 0;
for i := 0 to n do
begin
W[i,i] := Q[i];
C[i,i] := 0;
R[i,i] := B[i];
end;
for m := 1 to n do
begin
for i := 0 to n-m do
begin
j := i + m;
W[i,j] := W[i,j-1] + P[j] + Q[i];
Cij := bd;
for k := i+1 to j do
begin
if Cij > (W[i,j] + C[i,k-1] + C[k,j])
then
begin
inc(count);
Cij := W[i,j] + C[i,k-1] + C[k,j];
x := k;
end;
end;
C[i,j] := Cij;
r[i,j] := A[x];
end;
end;
self.Series1.AddXY(n,count*ln(sqrt(count)));
self.Series2.AddXY(n,n*n*n);
new(tree);
BuildTree(tree,0,n);
tree^.left := nil;
tree^.right := nil;
dispose(tree);
end;
end;
end.