选择排序.frm

来自「算法教案」· FRM 代码 · 共 114 行

FRM
114
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "选择算法(增序)"
   ClientHeight    =   5115
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   7800
   LinkTopic       =   "Form1"
   ScaleHeight     =   5115
   ScaleWidth      =   7800
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command1 
      Caption         =   "排序"
      Height          =   615
      Left            =   6120
      TabIndex        =   6
      Top             =   2640
      Width           =   1215
   End
   Begin VB.TextBox Text1 
      BackColor       =   &H0000FFFF&
      Height          =   495
      Left            =   6120
      TabIndex        =   5
      Top             =   1200
      Width           =   1095
   End
   Begin VB.ListBox List2 
      BackColor       =   &H00FF0000&
      Height          =   3120
      ItemData        =   "选择排序.frx":0000
      Left            =   3120
      List            =   "选择排序.frx":0002
      TabIndex        =   1
      Top             =   960
      Width           =   2175
   End
   Begin VB.ListBox List1 
      BackColor       =   &H00FF0000&
      Height          =   3120
      ItemData        =   "选择排序.frx":0004
      Left            =   240
      List            =   "选择排序.frx":0006
      TabIndex        =   0
      Top             =   960
      Width           =   2055
   End
   Begin VB.Label Label3 
      Caption         =   "输入数据"
      Height          =   375
      Left            =   6240
      TabIndex        =   4
      Top             =   480
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "排序后的数据"
      Height          =   375
      Left            =   3000
      TabIndex        =   3
      Top             =   480
      Width           =   2175
   End
   Begin VB.Label Label1 
      Caption         =   "输入的原始数据"
      Height          =   375
      Left            =   360
      TabIndex        =   2
      Top             =   480
      Width           =   1815
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim d(1 To 128) As Integer
Dim ct As Integer
Function adj(a As String, n As Integer) As String
    Dim sa As String
    sa = a: na = Len(a)
    For i = 1 To n - na
        sa = " " + sa
    Next i
    adj = sa
End Function
Private Sub Command1_Click()
    List2.Clear
    For i = 1 To ct - 1  '对数组d中的ct个数据排序
        k = i            '寻找d(i)到d(ct)范围内最小数据d(k)
        For j = i + 1 To ct
            If d(j) < d(k) Then
                kt = d(j): d(j) = d(k): d(k) = kt
            End If
        Next j
    Next i
    For i = 1 To ct
        List2.AddItem adj(Str(i), 3) + adj(Str(d(i)), 6)
    Next i
    ct = 0
    List1.AddItem ""
    List2.AddItem ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        ct = ct + 1
        d(ct) = Val(Text1.Text)
        List1.AddItem adj(Str(ct), 3) + adj(Str(d(ct)), 6)
        Text1.Text = "": Text1.SetFocus
    End If
End Sub

⌨️ 快捷键说明

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