Hi Silvia,
I'm not sure if this will solve your problem, but if I read your code right you neglect to determine which one is the larger of the child nodes before you swap with the root. That might look something like this:
Delphi-Quellcode:
procedure TBinTree.BuildHeap;
var Larger: TBinTree;
begin
// Lazy evaluation of boolean expressions needs to be switched on for this to work
Larger := Left;
if not Assigned(Larger) then
Larger := Right else
if Assigned(Right) and (Left.Value < Right.Value) then
LargerSon := Right;
if Assigned(Larger) and (Value < Larger.Value) then begin
Exchange(Larger,self);
Larger.BuildHeap;
end;
end;
If that doesn't do it, we'll need to look again.