堆排序的步骤有哪些?用堆排序对数组2,9,7,6,5,8进行排序,写出过程
- 提问者网友:人傍凄凉立暮秋
- 2021-07-28 11:11
- 五星知识达人网友:逃夭
- 2021-07-28 12:43
Private Sub Command1_Click()
Dim a(99) As Integer
Randomize
Form2.AutoRedraw = True
Dim i As Integer, j As Integer, temp As Integer
For i = 0 To 99
a(i) = Int(Rnd * 500 + 20) '
If a(i) > 500 Then
a(i) = a(i) - 20
End If
Print a(i) & " "; '在窗体上输出原始数据
Next i
For i = 0 To 99 '冒泡排序
For j = 0 To 98 - i
If (a(j) > a(j + 1)) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next j
Next i
Print
For i = 0 To 99 '在窗体上输出排序后的数据
Text1.Text = Text1.Text & " " & a(i)
Next i
End Sub
这是一个排序示例,你参考下