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

📄 sort.frm

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Appearance      =   0  'Flat
   BackColor       =   &H80000000&
   Caption         =   "七种常见的排序算法"
   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          =   315
      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            =   "88"
      Top             =   360
      Width           =   1335
   End
   Begin VB.ComboBox cmbSorts 
      Appearance      =   0  'Flat
      Height          =   315
      Left            =   2400
      Style           =   2  'Dropdown List
      TabIndex        =   10
      Top             =   4800
      Width           =   2535
   End
   Begin VB.CommandButton Command2 
      Appearance      =   0  'Flat
      Caption         =   "开始排序--->"
      Height          =   375
      Left            =   2400
      TabIndex        =   11
      Top             =   5160
      Width           =   2535
   End
   Begin VB.CommandButton Command1 
      Appearance      =   0  'Flat
      Caption         =   "<----随机产生数组"
      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       =   &H80000000&
      Caption         =   "循环次数:"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   2400
      TabIndex        =   8
      Top             =   2280
      Width           =   612
   End
   Begin VB.Label lblDuration 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000000&
      Caption         =   "持续时间:"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   2400
      TabIndex        =   7
      Top             =   1920
      Width           =   612
   End
   Begin VB.Label lblEnd 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000000&
      Caption         =   "结束时间:"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   2400
      TabIndex        =   6
      Top             =   1560
      Width           =   612
   End
   Begin VB.Label lblBegin 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000000&
      Caption         =   "开始时间:"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   2400
      TabIndex        =   5
      Top             =   1320
      Width           =   612
   End
   Begin VB.Label Label3 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000000&
      Caption         =   "数组大小"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   2400
      TabIndex        =   2
      Top             =   360
      Width           =   576
   End
   Begin VB.Label Label2 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000000&
      Caption         =   "排序后数据"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   5040
      TabIndex        =   12
      Top             =   120
      Width           =   720
   End
   Begin VB.Label Label1 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000000&
      Caption         =   "未排序数据"
      ForeColor       =   &H80000008&
      Height          =   192
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   720
   End
End
Attribute VB_Name = "Form1"
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 = "开始时间: " & 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 = "循环次数: " & Format$(gIterations, "#,#")
    lblEnd = "结束时间: " & Timer
    lblDuration = "持续时间: " & Timer - I & " 秒!"
    
    For I = 0 To UBound(mArray)
        lstSorted.AddItem mArray(I)
    Next

    MousePointer = 0

End Sub

Private Sub Form_Load()

    cmbOrder.AddItem "升序"
    cmbOrder.AddItem "降序"
    cmbOrder.ListIndex = 0

    cmbSorts.AddItem "冒泡排序法"
    cmbSorts.AddItem "插入排序法"
    cmbSorts.AddItem "Bucket排序法"
    cmbSorts.AddItem "选择排序法"
    cmbSorts.AddItem "Shell排序法"
    cmbSorts.AddItem "快速排序法"
    cmbSorts.AddItem "Heap排序法"
    cmbSorts.ListIndex = 0

    lstUnsorted.AddItem "-1322"
    lstUnsorted.AddItem "2171"
    lstUnsorted.AddItem "-511"
    ReDim mArray(0 To 2)
    mArray(0) = -1322
    mArray(1) = 2171
    mArray(2) = -511

End Sub

⌨️ 快捷键说明

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