📄 cxc4.frm
字号:
Top = 1680
Width = 3735
End
Begin VB.Label Label10
Alignment = 2 'Center
BackColor = &H00C0FFC0&
Caption = "您输入的待排序序列为:"
Height = 255
Left = 5280
TabIndex = 17
Top = 1560
Width = 4935
End
Begin VB.Label Label11
Alignment = 2 'Center
BackColor = &H00C0FFC0&
Caption = "经希尔排序后递增序列为:"
Height = 255
Left = 5280
TabIndex = 16
Top = 3000
Width = 4935
End
Begin VB.Label Label12
Alignment = 2 'Center
BackColor = &H00C0FFC0&
Caption = "经希尔排序后递减序列为:"
Height = 255
Left = 5280
TabIndex = 15
Top = 5400
Width = 4935
End
End
Attribute VB_Name = "cxc04"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'**********************************************
'* desinded dy 丞相 E_mail:cxc-0378@163.com *
'**********************************************
Dim i, M, k As Integer
Dim a(100), c(100), d(10) As Integer
Dim b(10) As Variant
Sub ShellSort(MyArray(), ByVal nOrder As Integer) '希尔排序主程序
Dim Distance
Dim Size
Dim Index
Dim NextElement
Dim TEMP
Dim gIterations
Size = UBound(MyArray) - LBound(MyArray) + 1
Distance = 1
While (Distance <= Size)
Distance = 2 * Distance
Wend
Distance = (Distance / 2) - 1
While (Distance > 0)
NextElement = LBound(MyArray) + Distance
While (NextElement <= UBound(MyArray))
Index = NextElement
Do
If Index >= (LBound(MyArray) + Distance) Then
If nOrder = 0 Then
If MyArray(Index) < MyArray(Index - Distance) Then
TEMP = MyArray(Index)
MyArray(Index) = MyArray(Index - Distance)
MyArray(Index - Distance) = TEMP
Index = Index - Distance
gIterations = gIterations + 1
Else
Exit Do
End If
ElseIf nOrder = 1 Then
If MyArray(Index) >= MyArray(Index - Distance) Then
TEMP = MyArray(Index)
MyArray(Index) = MyArray(Index - Distance)
MyArray(Index - Distance) = TEMP
Index = Index - Distance
gIterations = gIterations + 1
Else
Exit Do
End If
End If
Else
Exit Do
End If
Loop
NextElement = NextElement + 1
gIterations = gIterations + 1
Wend
Distance = (Distance - 1) / 2
gIterations = gIterations + 1
Wend
End Sub
Private Sub Form_Load()
cxc04.Left = (Screen.Width - Width) / 2
cxc04.Top = (Screen.Height - Height) / 2
i = 0
a(0) = 5: a(1) = 6: a(2) = 12: a(3) = 13: a(4) = 15: a(5) = 16: a(6) = 17: a(7) = 18
a(8) = 5: a(9) = 6: a(10) = 12: a(11) = 13: a(12) = 15: a(13) = 18
a(14) = 5: a(15) = 6: a(16) = 12: a(17) = 13: a(18) = 15: a(19) = 16: a(20) = 17: a(21) = 18
a(22) = 5: a(23) = 6: a(24) = 12: a(25) = 13: a(26) = 15: a(27) = 18
a(28) = 5: a(29) = 6: a(30) = 12: a(31) = 13: a(32) = 15: a(33) = 16: a(34) = 17: a(35) = 18
a(36) = 5: a(37) = 6: a(38) = 12: a(39) = 13: a(40) = 15: a(41) = 18
a(42) = 5: a(43) = 6: a(44) = 12: a(45) = 13: a(46) = 15: a(47) = 16: a(48) = 17: a(49) = 18
a(50) = 5: a(51) = 6: a(52) = 12: a(53) = 13: a(54) = 15: a(55) = 18
a(56) = 5: a(57) = 6: a(58) = 12: a(59) = 13: a(60) = 15: a(61) = 16: a(62) = 17: a(63) = 18
a(64) = 5: a(65) = 6: a(66) = 12: a(67) = 13: a(68) = 15: a(69) = 18
c(0) = 0: c(1) = 1: c(2) = 2: c(3) = 3: c(4) = 4: c(5) = 5: c(6) = 6: c(7) = 7: c(8) = 8: c(9) = 9
d(0) = 0: d(1) = 1: d(2) = 2: d(3) = 3: d(4) = 4: d(5) = 5: d(6) = 6: d(7) = 7: d(8) = 8: d(9) = 9
End Sub
Private Sub Image1_Click()
Image1.Picture = LoadPicture("D:\Documents and Settings\image\toolbar_shuoming.bmp")
End Sub
Private Sub Image3_Click()
Timer1.Enabled = True
End Sub
Private Sub Image5_Click()
Call Timer1_Timer
End Sub
Private Sub Image6_Click()
Timer1.Enabled = True
End Sub
Private Sub Image8_Click()
cxc04.Hide
cxc02.Show
End Sub
Private Sub Label1_Click()
List1.AddItem ("希尔排序(递增)自动运行显示:")
List1.AddItem ("shellsort()")
List1.AddItem ("{")
List1.AddItem ("int t=3,k;")
List1.AddItem ("int s[]={5,3,1};")
List1.AddItem ("for(k=0;k<t;k++)")
List1.AddItem ("shellinsert(s[k]);")
List1.AddItem ("}")
List1.AddItem ("/********************/")
List1.AddItem ("shellinsert(int s)")
List1.AddItem ("{")
List1.AddItem ("int i,j,m=100;")
List1.AddItem ("for(j=i-s;i<=m;++i)")
List1.AddItem ("if(r[i].key<r[i-s].key)")
List1.AddItem ("{")
List1.AddItem ("r[0]=r[i];")
List1.AddItem ("{for(j=i-s;j>0&&(r[0].key<r[j].key);j-=s)")
List1.AddItem ("r[j+s]=r[j];}")
List1.AddItem ("r[j+s]=r[0];")
List1.AddItem ("}")
End Sub
Private Sub Label13_Click() '递减排序
Dim textstr As String
Call ShellSort(b, 1)
For i = 0 To 9
textstr = textstr + Str$(b(i)) + Space(1)
List3.AddItem "第" + Str$(i + 1) + "趟:" + textstr
Next i
End Sub
Private Sub Label2_Click() '自动运行
Timer1.Enabled = True
Timer2.Enabled = True
End Sub
Private Sub Label3_Click() '暂停
Timer1.Enabled = False
Timer2.Enabled = False
End Sub
Private Sub Label4_Click() '单步
Call Timer1_Timer
Call Timer2_Timer
End Sub
Private Sub Label5_Click()
cxc06.Show
End Sub
Private Sub Label6_Click() '继续
Timer1.Enabled = True
Timer2.Enabled = True
End Sub
Private Sub Label7_Click() '输入数据
Dim i As Integer
Dim textstr As String
For i = 0 To 9
b(i) = InputBox("请逐个输入待排序序列(10个):")
If b(i) = "" Then
Exit For
End If
textstr = textstr + Str$(b(i)) + Space(1)
Text1.Text = textstr
Next i
End Sub
Private Sub Label8_Click() '递增排序
Dim textstr As String
Call ShellSort(b, 0)
For i = 1 To 10
textstr = textstr + Str$(b(i)) + Space(1)
List2.AddItem "第" + Str$(i) + "趟:" + textstr
Next i
End Sub
Private Sub Label9_Click()
cxc04.Hide
cxc02.Show
End Sub
Private Sub Timer1_Timer() '时钟
If (i <= 100) Then
List1.Selected(a(i)) = True
End If
i = i + 1
End Sub
Private Sub Timer2_Timer()
If (M <= 10) Then
List2.Selected(c(M)) = True
End If
M = M + 1
End Sub
Private Sub Timer3_Timer()
If (k <= 10) Then
List3.Selected(d(k)) = True
End If
k = k + 1
End Sub
Private Sub Timer4_Timer()
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -