+

来自「筛选和冒泡排序的代码」· 代码 · 共 51 行

TXT
51
字号
VERSION 5.00
Begin VB.Form 冒泡排序 
   Caption         =   "Form2"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form2"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
End
Attribute VB_Name = "冒泡排序"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Sort(a() As Integer)
Dim i As Integer, j As Integer
Dim temp As Integer
For i = 1 To UBound(a) - 1
    For j = 1 To UBound(a) - i
        If a(j) > a(j + 1) Then
            temp = a(j)
            a(j) = a(j + 1)
            a(j + 1) = temp
        End If
    
    Next
Next
End Sub

Private Sub Form_click()
Dim Mdarray(10) As Integer
Dim i As Integer
Print "排序前:"
For i = 1 To 10
    Mdarray(i) = Int(100 * Rnd(2))
    Print Mdarray(i);
Next
Print
Print "排序后:"
Call Sort(Mdarray)
For i = 1 To 10
    
    Print Mdarray(i);
Next
Print

End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?