Sorting algorithms/Heapsort: Difference between revisions

(Added VBA)
(→‎{{header|FreeBASIC}}: fix more bugs)
Line 1,553:
Dim As Long lb = LBound(hs)
 
While root * 2 + 1 <= end_
Dim As ULong child = root * 2 + 1
If (child + 1 <= end_) AndAndAlso (hs(lb + child) < hs(lb + child + 1)) Then
child = child + 1
End If
Line 1,570:
Dim As Long lb = LBound(hs)
Dim As ULong count = UBound(hs) - lb + 1
Dim As Long start = lb + (count - 2) \ 2
Dim As ULong end_ = count - 1
 
While start >= 0
siftdown(hs(), start, countend_)
start = start - 1
Wend
 
Dim As ULong end_ = count - 1
While end_ > 0
Swap hs(lb + end_), hs(lb)
siftdown(hs(), 0, end_)
end_ = end_ - 1
siftdown(hs(), 0, end_)
Wend
End Sub
Anonymous user