VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   12
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "冒泡法排序"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   555
      Left            =   2880
      TabIndex        =   0
      Top             =   2580
      Width           =   1695
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Base 1
Private Sub Command1_Click()
     Dim iA(1 To 10)
     n = 6
     iA(1) = 8: iA(2) = 6: iA(3) = 9: iA(4) = 3: iA(5) = 2: iA(6) = 7
     Print "冒泡法排序数据变化过程"
     Print "      8, 6, 9, 3, 2, 7"
     Print "-----------------------------"
     For i = 1 To n - 1              ' 进行n-1遍比较
       ' 对第i遍比较时，初始假定第i个元素最小
       For j = n To i + 1 Step -1          ' 在数组 i~n个元素中选最小元素的下标
            If iA(j) < iA(j - 1) Then
              t = iA(j)
              iA(j) = iA(j - 1)
              iA(j - 1) = t
            End If
       Next j
       
       Print "i="; i; Spc(i * 3 - 3);
       For k = i To n
        Print iA(k);
       Next k
       Print
    Next i

End Sub
