VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "矩阵排序例"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   735
      Left            =   1920
      TabIndex        =   0
      Top             =   2520
      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%(20), ic%(4, 5)
     Print "------排序前-------"
     k = 1
     For i = 1 To 4             ' 进行n-1遍比较
       For j = 1 To 5
        ic(i, j) = Int(Rnd * 21 + 20)
        Print ic(i, j);
        iA(k) = ic(i, j)
        k = k + 1
       Next j
       Print
     Next i
      For i = 1 To 19              ' 对第i遍比较时，初始假定第i个元素最小
        For j = 20 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
        t = iA(i)                   'i~n个元素中选出的最小元素与第i个元素交换
     Next i
     Print
        Print "------排序后-------"
 
    k = 1
     For i = 1 To 4             ' 进行n-1遍比较
       For j = 1 To 5
        ic(i, j) = iA(k)
        Print ic(i, j);
        k = k + 1
       Next j
       Print
     Next i
End Sub
