Forum: Object-Pascal / Delphi-Language
Delphi
by tigerman33,
12. Mai 2006
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:
procedure TBinTree.BuildHeap;
var Larger: TBinTree;
begin
// Lazy evaluation of boolean expressions needs to be switched on for this to work
Larger := Left;
Forum: Object-Pascal / Delphi-Language
Delphi
by tigerman33,
2. Mai 2006
Wikipedia article explaining heapsort/sift:
PS: Yeah, I know this isn't really C-code. Just wanted the syntax highlighting... :)
Forum: Object-Pascal / Delphi-Language
Delphi
by tigerman33,
1. Mai 2006
Hi,
if you already have a binary tree, you should be able to transform it into a heap by successively performing a so-called sift operation on the nodes from the bottom up. A sift operation means exchanging the given node with the tree root. Then if necessary, you exchange that node with the larger one of its two sons to keep the ordering. After that, recursively repeat on the just-changed...