⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sort.frm

📁 基于VB的冒泡排序的算法程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmSort 
   Appearance      =   0  'Flat
   BackColor       =   &H80000005&
   Caption         =   "All Sorts"
   ClientHeight    =   5820
   ClientLeft      =   1455
   ClientTop       =   1710
   ClientWidth     =   7365
   ForeColor       =   &H80000008&
   LinkTopic       =   "Form1"
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   5820
   ScaleWidth      =   7365
   Begin VB.ComboBox cmbOrder 
      Appearance      =   0  'Flat
      Height          =   300
      Left            =   2400
      Style           =   2  'Dropdown List
      TabIndex        =   9
      Top             =   4440
      Width           =   2535
   End
   Begin VB.TextBox txtSize 
      Appearance      =   0  'Flat
      Height          =   285
      Left            =   3600
      TabIndex        =   3
      Text            =   "100"
      Top             =   360
      Width           =   1335
   End
   Begin VB.ComboBox cmbSorts 
      Appearance      =   0  'Flat
      Height          =   300
      Left            =   2400
      Style           =   2  'Dropdown List
      TabIndex        =   10
      Top             =   4920
      Width           =   2535
   End
   Begin VB.CommandButton Command2 
      Appearance      =   0  'Flat
      Caption         =   "S&ort Data --->"
      Height          =   375
      Left            =   2400
      TabIndex        =   11
      Top             =   5280
      Width           =   2535
   End
   Begin VB.CommandButton Command1 
      Appearance      =   0  'Flat
      Caption         =   "<--- &Generate Data"
      Height          =   375
      Left            =   2400
      TabIndex        =   4
      Top             =   720
      Width           =   2535
   End
   Begin VB.ListBox lstSorted 
      Appearance      =   0  'Flat
      Height          =   5100
      Left            =   5040
      TabIndex        =   13
      Top             =   360
      Width           =   2175
   End
   Begin VB.ListBox lstUnsorted 
      Appearance      =   0  'Flat
      Height          =   5100
      Left            =   120
      TabIndex        =   1
      Top             =   360
      Width           =   2175
   End
   Begin VB.Label lblIterations 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "Loop count:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   2400
      TabIndex        =   8
      Top             =   2280
      Width           =   1035
   End
   Begin VB.Label lblDuration 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "Duration:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   2400
      TabIndex        =   7
      Top             =   1920
      Width           =   795
   End
   Begin VB.Label lblEnd 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "End time:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   2400
      TabIndex        =   6
      Top             =   1560
      Width           =   810
   End
   Begin VB.Label lblBegin 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "Begin time:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   2400
      TabIndex        =   5
      Top             =   1320
      Width           =   960
   End
   Begin VB.Label Label3 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "S&ize of array:"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   2400
      TabIndex        =   2
      Top             =   360
      Width           =   1140
   End
   Begin VB.Label Label2 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "&Sorted"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   5040
      TabIndex        =   12
      Top             =   120
      Width           =   570
   End
   Begin VB.Label Label1 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000005&
      Caption         =   "&Unsorted"
      ForeColor       =   &H80000008&
      Height          =   195
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   780
   End
End
Attribute VB_Name = "frmSort"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim mArray()

Private Sub cmbSorts_Click()
    
    If cmbSorts.ListIndex > 4 Then
        cmbOrder.Enabled = False
    Else
        cmbOrder.Enabled = True
    End If

End Sub

Private Sub Command1_Click()
Dim I
Dim J

    If Len(Trim$(txtSize)) = 0 Then txtSize = "0"
    ReDim mArray(CDbl(txtSize) - 1)
    
    Randomize
    lstUnsorted.Clear
    For I = 0 To CDbl(txtSize) - 1
        J = Int((32767 - (-32768) + 1) * Rnd + (-32768))
        lstUnsorted.AddItem Str$(J)
        mArray(I) = J
    Next

    Command2.Enabled = True

End Sub

Private Sub Command2_Click()
Dim I

    MousePointer = 11

    lstSorted.Clear

    I = Timer
    lblBegin = "Begin time: " & I
    gIterations = 0

    Select Case cmbSorts.ListIndex
    Case 0
        Call BubbleSort(mArray(), cmbOrder.ListIndex)
    Case 1
        Call Insertion(mArray(), cmbOrder.ListIndex)
    Case 2
        Call Bucket(mArray(), cmbOrder.ListIndex)
    Case 3
        Call Selection(mArray(), cmbOrder.ListIndex)
    Case 4
        Call ShellSort(mArray(), cmbOrder.ListIndex)
    Case 5
        Call QuickSort(mArray(), 0, UBound(mArray))
    Case 6
        Call Heap(mArray())
    End Select
    
    lblIterations = "Loop count: " & Format$(gIterations, "#,#")
    lblEnd = "End time: " & Timer
    lblDuration = "Duration: " & Timer - I & " seconds!"
    
    For I = 0 To UBound(mArray)
        lstSorted.AddItem mArray(I)
    Next

    MousePointer = 0

End Sub

Private Sub Form_Load()

    cmbOrder.AddItem "Ascending"
    cmbOrder.AddItem "Descending"
    cmbOrder.ListIndex = 0

    cmbSorts.AddItem "Bubble"
    cmbSorts.AddItem "Insertion"
    cmbSorts.AddItem "Bucket"
    cmbSorts.AddItem "Selection"
    cmbSorts.AddItem "Shell"
    cmbSorts.AddItem "Quick"
    cmbSorts.AddItem "Heap"
    cmbSorts.ListIndex = 0

    lstUnsorted.AddItem "-13322"
    lstUnsorted.AddItem "21571"
    lstUnsorted.AddItem "-5111"
    ReDim mArray(0 To 2)
    mArray(0) = -13322
    mArray(1) = 21571
    mArray(2) = -5111

End Sub

⌨️ 快捷键说明

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