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

📄 cxc12.frm

📁 《数据结构》排序演示系统。实现6种内部排序。包括直接插入排序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form cxc12 
   BackColor       =   &H00C0FFC0&
   Caption         =   "堆排序(heapsort)"
   ClientHeight    =   7605
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   10875
   Icon            =   "cxc12.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   7605
   ScaleWidth      =   10875
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer2 
      Enabled         =   0   'False
      Interval        =   4000
      Left            =   9600
      Top             =   3960
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   600
      Left            =   4200
      Top             =   6480
   End
   Begin VB.ListBox List3 
      BackColor       =   &H00FFC0FF&
      Height          =   1320
      Left            =   5640
      TabIndex        =   14
      Top             =   5400
      Width           =   4455
   End
   Begin VB.ListBox List2 
      BackColor       =   &H00FFC0FF&
      Height          =   1320
      Left            =   5640
      TabIndex        =   13
      Top             =   3120
      Width           =   4455
   End
   Begin VB.TextBox Text1 
      BackColor       =   &H00FFC0FF&
      Height          =   855
      Left            =   5640
      TabIndex        =   12
      Text            =   "Text1"
      Top             =   1680
      Width           =   4455
   End
   Begin VB.ListBox List1 
      BackColor       =   &H00C0E0FF&
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   5460
      Left            =   720
      TabIndex        =   11
      Top             =   1440
      Width           =   3975
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFC0C0&
      Height          =   975
      Left            =   0
      TabIndex        =   0
      Top             =   -120
      Width           =   11000
      Begin VB.Image Image9 
         Height          =   240
         Index           =   0
         Left            =   8040
         Picture         =   "cxc12.frx":0CCA
         Top             =   240
         Width           =   240
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "导入程序"
         Height          =   255
         Index           =   2
         Left            =   1200
         TabIndex        =   10
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label12 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "自动运行"
         Height          =   255
         Left            =   2280
         TabIndex        =   9
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label11 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "暂  停"
         Height          =   255
         Left            =   3360
         TabIndex        =   8
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label10 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "单步运行"
         Height          =   255
         Left            =   5520
         TabIndex        =   7
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "继  续"
         Height          =   255
         Left            =   4440
         TabIndex        =   6
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label7 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "输入数据"
         Height          =   255
         Left            =   6720
         TabIndex        =   5
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label14 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "递增排序"
         ForeColor       =   &H80000008&
         Height          =   255
         Index           =   0
         Left            =   7800
         TabIndex        =   4
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label9 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "返  回"
         Height          =   255
         Left            =   9960
         TabIndex        =   3
         Top             =   600
         Width           =   855
      End
      Begin VB.Image Image13 
         Height          =   240
         Left            =   480
         Picture         =   "cxc12.frx":0DCC
         Top             =   240
         Width           =   270
      End
      Begin VB.Image Image12 
         Height          =   240
         Left            =   1440
         Picture         =   "cxc12.frx":0F0E
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image11 
         Height          =   225
         Left            =   2520
         Picture         =   "cxc12.frx":1010
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image10 
         Height          =   225
         Left            =   3720
         Picture         =   "cxc12.frx":110A
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image5 
         Height          =   270
         Left            =   5760
         Picture         =   "cxc12.frx":1204
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image6 
         Height          =   225
         Left            =   4680
         Picture         =   "cxc12.frx":1316
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image7 
         Height          =   240
         Left            =   6960
         Picture         =   "cxc12.frx":1410
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image8 
         Height          =   225
         Left            =   10200
         Picture         =   "cxc12.frx":1512
         Top             =   240
         Width           =   225
      End
      Begin VB.Label Label4 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "说  明"
         Height          =   255
         Left            =   120
         TabIndex        =   2
         Top             =   600
         Width           =   855
      End
      Begin VB.Image Image9 
         Height          =   240
         Index           =   1
         Left            =   9120
         Picture         =   "cxc12.frx":160C
         Top             =   240
         Width           =   240
      End
      Begin VB.Label Label13 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "递减排序"
         ForeColor       =   &H80000008&
         Height          =   255
         Index           =   1
         Left            =   8880
         TabIndex        =   1
         Top             =   600
         Width           =   855
      End
   End
   Begin VB.Label Label5 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "经堆排序后递减序列为:"
      Height          =   255
      Left            =   5760
      TabIndex        =   17
      Top             =   5040
      Width           =   4335
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "经堆排序后递增序列为:"
      Height          =   255
      Left            =   5760
      TabIndex        =   16
      Top             =   2880
      Width           =   4335
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "您输入的待排序序列为:"
      Height          =   255
      Left            =   5760
      TabIndex        =   15
      Top             =   1440
      Width           =   4335
   End
End
Attribute VB_Name = "cxc12"
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, k, gIterations As Integer
Dim a(100), c(10) As Integer
Dim b(10) As Variant

Private Sub Form_Load()
cxc12.Left = (Screen.Width - Width) / 2
cxc12.Top = (Screen.Height - Height) / 2
i = 0
a(0) = 3: a(1) = 28: a(2) = 29: a(3) = 14: a(4) = 15: a(5) = 16: a(6) = 17: a(7) = 18: a(8) = 19: a(9) = 20
 a(10) = 3: a(11) = 28: a(12) = 29: a(13) = 14: a(14) = 15: a(15) = 22
 a(16) = 3: a(17) = 28: a(18) = 29: a(19) = 14: a(20) = 15: a(21) = 16: a(22) = 17: a(23) = 18: a(24) = 19: a(25) = 20
 a(26) = 3: a(27) = 28: a(28) = 29: a(29) = 14: a(30) = 15: a(31) = 22
 a(32) = 3: a(33) = 28: a(34) = 29: a(35) = 14: a(36) = 15: a(37) = 16: a(38) = 17: a(39) = 18: a(40) = 19: a(41) = 20
 a(42) = 3: a(43) = 28: a(44) = 29: a(45) = 14: a(46) = 15: a(47) = 22
 a(48) = 3: a(49) = 28: a(50) = 29: a(51) = 14: a(52) = 15: a(53) = 16: a(54) = 17: a(55) = 18: a(56) = 19: a(57) = 20
 a(58) = 3: a(59) = 28: a(60) = 29: a(61) = 14: a(62) = 15: a(63) = 22
 a(64) = 3: a(65) = 28: a(66) = 29: a(67) = 14: a(68) = 15: a(69) = 16: a(70) = 17: a(71) = 18: a(72) = 19: a(73) = 20
 a(74) = 3: a(75) = 28: a(76) = 29: a(77) = 14: a(78) = 15: a(79) = 22
 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
End Sub

Private Sub Label1_Click(Index As Integer)
List1.AddItem ("heapsort(int m)") '0
List1.AddItem ("{") '1
List1.AddItem ("int i;")
List1.AddItem ("buildheap(m);") '3
List1.AddItem ("for (i=m;i>1;i--){") '4
List1.AddItem ("r[0].key=r[1].key;r[1].key=r[i].key;r[i].key=r[0].key;") '5
List1.AddItem ("heapify(1,i-1);") '6
List1.AddItem ("}")
List1.AddItem ("}")
List1.AddItem ("/**************************************/")
List1.AddItem ("heapify(int low,int high)")
List1.AddItem ("{")
List1.AddItem ("int large;")
List1.AddItem ("rectype temp;")
List1.AddItem ("temp.key=r[low].key;") '14
List1.AddItem ("for(large=2*low;large<=high;large*=2){") '15
List1.AddItem ("if((large<high)&&(r[large].key<r[large+1].key))") '16
List1.AddItem ("large++;") '17
List1.AddItem ("if (temp.key>=r[large].key) break;") '18
List1.AddItem ("r[low].key=r[large].key;") '19
List1.AddItem ("low=large;") '20
List1.AddItem ("}")
List1.AddItem ("r[low].key=temp.key;") '22
List1.AddItem ("}")
List1.AddItem ("/***********************************/")
List1.AddItem ("buildheap (m)") '25
List1.AddItem ("{")
List1.AddItem ("int i;") '27
List1.AddItem ("for (i=m/2;i>0;i--)") '28
List1.AddItem ("heapify(i,m);") '29
List1.AddItem ("}")

End Sub

Private Sub Label10_Click()
Call Timer1_Timer
Call Timer2_Timer
End Sub

Private Sub Label11_Click()
Timer1.Enabled = False
Timer2.Enabled = False
End Sub

Private Sub Label12_Click()
Timer1.Enabled = True
Timer2.Enabled = True
End Sub

Private Sub Label14_Click(Index As Integer)
Dim textstr As String
Call Heapsort(b)
For i = 1 To 10
textstr = textstr + Str$(b(i)) + Space(1)
List2.AddItem "第" + Str$(i) + "趟:" + textstr
Next i
End Sub

Private Sub Label4_Click()
cxc11.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 = 1 To 10
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
Sub Heapsort(MyArray())
Dim Index
Dim Size
Dim TEMP

    Size = UBound(MyArray)
    
    Index = 1
    While (Index <= Size)
        Call HeapSiftup(MyArray(), Index)
        Index = Index + 1
        gIterations = gIterations + 1
    Wend

    Index = Size
    While (Index > 0)
        TEMP = MyArray(0)
        MyArray(0) = MyArray(Index)
        MyArray(Index) = TEMP
        Call HeapSiftdown(MyArray(), Index - 1)
        Index = Index - 1
        gIterations = gIterations + 1
    Wend

End Sub
 

Sub HeapSiftdown(MyArray(), M)
Dim Index
Dim Parent
Dim TEMP

    Index = 0
    Parent = 2 * Index

    Do While (Parent <= M)
        
        If (Parent < M And MyArray(Parent) < MyArray(Parent + 1)) Then
            Parent = Parent + 1
        End If

        If MyArray(Index) >= MyArray(Parent) Then
            Exit Do
        End If

        TEMP = MyArray(Index)
        MyArray(Index) = MyArray(Parent)
        MyArray(Parent) = TEMP
        
        Index = Parent
        Parent = 2 * Index

        gIterations = gIterations + 1
    Loop
End Sub

Sub HeapSiftup(MyArray(), M)
Dim Index
Dim Parent
Dim TEMP

    Index = M
    Do While (Index > 0)
        Parent = Int(Index / 2)

        If MyArray(Parent) >= MyArray(Index) Then
            Exit Do
        End If
        
        TEMP = MyArray(Index)
        MyArray(Index) = MyArray(Parent)
        MyArray(Parent) = TEMP

        Index = Parent
        gIterations = gIterations + 1
    Loop
    
End Sub

Private Sub Label9_Click()
cxc02.Show
cxc12.Hide
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 (k <= 10) Then
List2.Selected(c(k)) = True
End If
 k = k + 1
End Sub

⌨️ 快捷键说明

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