Private Sub Command1_Click() Dim a() a = Array("17", "13", "25", "67", "70", "32", "79", "42", "69", "41") For i = LBound(a) To UBound(a) Print a(i) & " "; Next i
'冒泡排序法 Print Print "用冒泡排序法排序" For i = UBound(a) To LBound(a) + 1 Step -1 For j = 0 To UBound(a) - 1 If a(j) > a(j + 1) Then temp = a(j): a(j) = a(j + 1): a(j + 1) = temp Next j Next i For i = LBound(a) To UBound(a) Print a(i) & " "; Next i
'选择排序法 Print Print "用选择排序法排序" For i = LBound(a) To UBound(a) - 1 k = i For j = i + 1 To UBound(a) If a(j) < a(k) Then j = k Next j temp = a(i): a(i) = a(k): a(k) = temp Next i For i = LBound(a) To UBound(a) Print a(i) & " "; Next i End Sub