Sorting algorithms/Heapsort: Difference between revisions
Content added Content deleted
(→{{header|FreeBASIC}}: fix more bugs) |
(→{{header|VBA}}: fix bugs) |
||
Line 4,003: | Line 4,003: | ||
Dim temp As Integer |
Dim temp As Integer |
||
While root * 2 + 1 < eend |
While root * 2 + 1 <= eend |
||
Dim child As Long : child = root * 2 + 1 |
Dim child As Long : child = root * 2 + 1 |
||
If (child + 1 < eend |
If (child + 1 <= eend) Then |
||
child |
If (list(lb + child) < list(lb + child + 1)) Then |
||
child = child + 1 |
|||
End If |
|||
End If |
End If |
||
If list(lb + root) < list(lb + child) Then |
If list(lb + root) < list(lb + child) Then |
||
Line 4,023: | Line 4,025: | ||
Dim lb As Long : lb = LBound(list) |
Dim lb As Long : lb = LBound(list) |
||
Dim count As Long : count = UBound(list) - lb + 1 |
Dim count As Long : count = UBound(list) - lb + 1 |
||
Dim start As Long : start = |
Dim start As Long : start = (count - 2) \ 2 |
||
⚫ | |||
While start >= 0 |
While start >= 0 |
||
SiftDown list(), start, |
SiftDown list(), start, eend |
||
start = start - 1 |
start = start - 1 |
||
Wend |
Wend |
||
⚫ | |||
Dim temp As Integer |
Dim temp As Integer |
||
Line 4,038: | Line 4,040: | ||
list(lb) = temp |
list(lb) = temp |
||
⚫ | |||
eend = eend - 1 |
eend = eend - 1 |
||
⚫ | |||
Wend |
Wend |
||
End Sub</lang> |
End Sub</lang> |