VB选择排序

Private Sub Command1_Click()
Dim arr(1 To 10000) As Integer
Dim i, j, k, n, temp As Integer

n = Val(InputBox("input total num :"))

For i = 1 To n
    arr(i) = Val(InputBox("input num :"))
Next i

For i = 1 To n
    k = i
    
    For j = i + 1 To n
        If arr(j) < arr(k) Then
            k = j
        End If
    Next j
    
    If k <> i Then
        temp = arr(i)
        arr(i) = arr(k)
        arr(k) = temp
    End If
Next i

For i = 1 To n
    Print arr(i)
Next i
End Sub
上一篇:excel中vba使用


下一篇:Primary Key