-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.pas
More file actions
57 lines (46 loc) · 1.22 KB
/
Tree.pas
File metadata and controls
57 lines (46 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
unit Tree;
interface
uses
usesUnit;
function CreateElement(fLevel: Integer; fConstr: TConstructionType; fAmount: Integer = 0): tRec;
function trCreateRoot: ptRec;
procedure trDeleteTree(var ptNode: ptRec);
function trAddElement(const ptNode: pTRec; fLevel: Integer; fConstr: TConstructionType; fAmount: Integer = 0): pTRec;
implementation
uses SysUtils;
function CreateElement;
begin
Result.fLevel := fLevel;
Result.fConstr := fConstr;
Result.fAmount := fAmount;
end;
function trCreateRoot;
begin
New(result);
result^:=CreateElement(-1, C_modul, 0);
end;
procedure trDeleteTree(var ptNode: ptRec);
var tempPT: ptRec;
count: integer;
begin
tempPT:=ptNode;
if tempPT<>nil
then begin
for count:=0 to Length(tempPT^.fInternal)-1
do
trDeleteTree(tempPT^.fInternal[count]);
Dispose(tempPT);
end;
end;
function trAddElement;
var tempLen: Integer;
addedElement: tRec;
begin
addedElement:=CreateElement(fLevel, fConstr, fAmount);
tempLen := Length(ptNode^.fInternal);
SetLength(ptNode^.fInternal, tempLen+1);
New(ptNode^.fInternal[tempLen]);
ptNode^.fInternal[tempLen]^:=addedElement;
result:=ptNode^.fInternal[tempLen];
end;
end.