First, I'd build the BINARY-TREE support into your record. like this:

myrecord = record

data : string {or whatever};

parent : word;

children : array[1..2] of word;{or 1..whatever}

end;

then you're VAR statement is something like this.

myvar : array[1..100] of record;

Then you can put the value "0" in the CHILDREN or PARENT area to indicate if the record is the ROOT, OR LEAF of the tree.

like in this tree.

R1

R2 R3

R4 R5 R6 R7

R8

where R1 is root

R2's parent is R1 its children are R4 and R5.

R3's parent is R1, its children are R6 and R7.

R4 and R5's parent is R2, and they each have NO children.

R6's parent is R3. It also has NO children.

R7's parent is R3, its only child is R8.

Here's how to set up this tree:

myvar[1].parent := 0; {Has NO parents,therefore, it's the root}

myvar[1].children[1] := 2; {child 1 is record #2 -- myvar[2])

myvar[1].children[2] := 3; {child 2 is record #3 -- myvar[3]}

myvar[2].parent := 1; {parent is myvar[1]}

myvar[2].children[1] := 4;

myvar[2].children[1] := 5;

myvar[3].parent := 1;

myvar[3].children[1] := 6;

myvar[3].children[2] := 7;

myvar[4].parent := 2;

myvar[4].children[1] := 0; {0, therefore, NO CHILDREN};

myvar[4].children[2] := 0; {still no children};

Myvar[5].parent := 2;

myvar[5].children[1] := 0;

myvar[5].children[2] := 0;

myvar[6].parent := 3;

myvar[6].children[1] := 0;

myvar[6].children[2] := 0;

myvar[7].parent := 3;

myvar[7].children[1] := 8; {it has at least 1 child}

myvar[7].children[2] := 0; { has NO second child}

myvar[8].parent := 7;

myvar.children[1] := 0;

myvar.children[2] := 0;

Ok.. let me know if this still makes sense.. Implement this into your program, and let me know the remaining problems...

This should get the Tree into memory, and onto the disk. Now, transversing the tree, will be the next problem, we'll work on this after you post the next problems you have .