Sorting algorithms/Heapsort: Difference between revisions
Content added Content deleted
(Added VBA) |
(→{{header|FreeBASIC}}: fix more bugs) |
||
Line 1,553: | Line 1,553: | ||
Dim As Long lb = LBound(hs) |
Dim As Long lb = LBound(hs) |
||
While root * 2 + 1 < end_ |
While root * 2 + 1 <= end_ |
||
Dim As ULong child = root * 2 + 1 |
Dim As ULong child = root * 2 + 1 |
||
If (child + 1 < end_) |
If (child + 1 <= end_) AndAlso (hs(lb + child) < hs(lb + child + 1)) Then |
||
child = child + 1 |
child = child + 1 |
||
End If |
End If |
||
Line 1,570: | Line 1,570: | ||
Dim As Long lb = LBound(hs) |
Dim As Long lb = LBound(hs) |
||
Dim As ULong count = UBound(hs) - lb + 1 |
Dim As ULong count = UBound(hs) - lb + 1 |
||
Dim As Long start = |
Dim As Long start = (count - 2) \ 2 |
||
⚫ | |||
While start >= 0 |
While start >= 0 |
||
siftdown(hs(), start, |
siftdown(hs(), start, end_) |
||
start = start - 1 |
start = start - 1 |
||
Wend |
Wend |
||
⚫ | |||
While end_ > 0 |
While end_ > 0 |
||
Swap hs(lb + end_), hs(lb) |
Swap hs(lb + end_), hs(lb) |
||
⚫ | |||
end_ = end_ - 1 |
end_ = end_ - 1 |
||
⚫ | |||
Wend |
Wend |
||
End Sub |
End Sub |