?? sort.frm
字號:
VERSION 5.00
Begin VB.Form Form1
Appearance = 0 'Flat
BackColor = &H80000000&
Caption = "七種常見的排序算法"
ClientHeight = 5820
ClientLeft = 1452
ClientTop = 1716
ClientWidth = 7368
ForeColor = &H80000008&
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 5820
ScaleWidth = 7368
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 = "開始排序--->"
Height = 375
Left = 2400
TabIndex = 11
Top = 5280
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 = 5208
Left = 5040
TabIndex = 13
Top = 360
Width = 2175
End
Begin VB.ListBox lstUnsorted
Appearance = 0 'Flat
Height = 5208
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 + -