冒泡排序.frm

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

FRM
109
字号
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       =   &H00FFFFFF&
      Height          =   495
      Left            =   6120
      TabIndex        =   5
      Top             =   1200
      Width           =   1095
   End
   Begin VB.ListBox List2 
      BackColor       =   &H00FFFFFF&
      Height          =   3120
      ItemData        =   "冒泡排序.frx":0000
      Left            =   3120
      List            =   "冒泡排序.frx":0002
      TabIndex        =   1
      Top             =   960
      Width           =   2175
   End
   Begin VB.ListBox List1 
      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
        For j = 1 To ct - i
            If d(j) < d(j + 1) Then
                k = d(j): d(j) = d(j + 1): d(j + 1) = k
            End If
        Next j
    Next i
    For i = 1 To ct
        List2.AddItem adj(Str(i), 3) + adj(Str(d(i)), 6)
    Next i
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 + -
显示快捷键?