Sorting algorithms/Heapsort: Difference between revisions

(→‎{{header|FreeBASIC}}: fix more bugs)
Line 4,003:
Dim temp As Integer
 
While root * 2 + 1 <= eend
Dim child As Long : child = root * 2 + 1
If (child + 1 <= eend) And (list(lb + child) < list(lb + child + 1)) Then
If (list(lb + child) =< list(lb + child + 1)) Then
child = child + 1
End If
End If
If list(lb + root) < list(lb + child) Then
Line 4,023 ⟶ 4,025:
Dim lb As Long : lb = LBound(list)
Dim count As Long : count = UBound(list) - lb + 1
Dim start As Long : start = lb + (count - 2) \ 2
Dim eend As Long : eend = count - 1
 
While start >= 0
SiftDown list(), start, counteend
start = start - 1
Wend
 
Dim eend As Long : eend = count - 1
Dim temp As Integer
 
Line 4,038 ⟶ 4,040:
list(lb) = temp
 
SiftDown list(), 0, eend
eend = eend - 1
 
SiftDown list(), 0, eend
Wend
End Sub</lang>
Anonymous user