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

📄 cxc8.frm

📁 《数据结构》排序演示系统。实现6种内部排序。包括直接插入排序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form cxc08 
   BackColor       =   &H00C0FFC0&
   Caption         =   "快速排序(quicksort)"
   ClientHeight    =   7995
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   10875
   Icon            =   "cxc8.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   20699.03
   ScaleMode       =   0  'User
   ScaleWidth      =   10875
   StartUpPosition =   2  '屏幕中心
   Begin VB.Timer Timer2 
      Enabled         =   0   'False
      Interval        =   4800
      Left            =   9720
      Top             =   4440
   End
   Begin VB.ListBox List3 
      BackColor       =   &H00FFC0FF&
      Height          =   1500
      Left            =   5640
      TabIndex        =   14
      Top             =   5760
      Width           =   4575
   End
   Begin VB.ListBox List2 
      BackColor       =   &H00FFC0FF&
      Height          =   1500
      Left            =   5640
      TabIndex        =   13
      Top             =   3360
      Width           =   4575
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   4320
      Top             =   6840
   End
   Begin VB.TextBox Text1 
      BackColor       =   &H00FFC0FF&
      Height          =   615
      Left            =   5640
      TabIndex        =   11
      Text            =   "Text1"
      Top             =   1920
      Width           =   4575
   End
   Begin VB.ListBox List1 
      BackColor       =   &H00C0E0FF&
      BeginProperty Font 
         Name            =   "新宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   5520
      Left            =   600
      TabIndex        =   10
      Top             =   1680
      Width           =   4095
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFC0C0&
      Height          =   975
      Left            =   0
      TabIndex        =   0
      Top             =   -120
      Width           =   11000
      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        =   12
         Top             =   600
         Width           =   855
      End
      Begin VB.Image Image9 
         Height          =   240
         Index           =   1
         Left            =   9120
         Picture         =   "cxc8.frx":0CCA
         Top             =   240
         Width           =   240
      End
      Begin VB.Label Label4 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "说  明"
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   600
         Width           =   855
      End
      Begin VB.Image Image9 
         Height          =   240
         Index           =   0
         Left            =   8040
         Picture         =   "cxc8.frx":0DCC
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image8 
         Height          =   225
         Left            =   10200
         Picture         =   "cxc8.frx":0ECE
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image7 
         Height          =   240
         Left            =   6960
         Picture         =   "cxc8.frx":0FC8
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image6 
         Height          =   225
         Left            =   4680
         Picture         =   "cxc8.frx":10CA
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image5 
         Height          =   270
         Left            =   5760
         Picture         =   "cxc8.frx":11C4
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image10 
         Height          =   225
         Left            =   3720
         Picture         =   "cxc8.frx":12D6
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image11 
         Height          =   225
         Left            =   2520
         Picture         =   "cxc8.frx":13D0
         Top             =   240
         Width           =   225
      End
      Begin VB.Image Image12 
         Height          =   240
         Left            =   1440
         Picture         =   "cxc8.frx":14CA
         Top             =   240
         Width           =   240
      End
      Begin VB.Image Image13 
         Height          =   240
         Left            =   480
         Picture         =   "cxc8.frx":15CC
         Top             =   240
         Width           =   270
      End
      Begin VB.Label Label9 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "返  回"
         Height          =   255
         Left            =   9960
         TabIndex        =   8
         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        =   7
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label7 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "输入数据"
         Height          =   255
         Left            =   6720
         TabIndex        =   6
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "继  续"
         Height          =   255
         Left            =   4440
         TabIndex        =   5
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label10 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "单步运行"
         Height          =   255
         Left            =   5520
         TabIndex        =   4
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label11 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "暂  停"
         Height          =   255
         Left            =   3360
         TabIndex        =   3
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label12 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "自动运行"
         Height          =   255
         Left            =   2280
         TabIndex        =   2
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "导入程序"
         Height          =   255
         Index           =   2
         Left            =   1200
         TabIndex        =   1
         Top             =   600
         Width           =   855
      End
   End
   Begin VB.Label Label5 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "经快速排序后递减序列为:"
      Height          =   255
      Left            =   5640
      TabIndex        =   17
      Top             =   5520
      Width           =   4575
   End
   Begin VB.Label Label3 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "经快速排序后递增序列为:"
      Height          =   255
      Left            =   5640
      TabIndex        =   16
      Top             =   3120
      Width           =   4575
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "您输入的待排序序列为:"
      Height          =   255
      Left            =   5640
      TabIndex        =   15
      Top             =   1560
      Width           =   4575
   End
End
Attribute VB_Name = "cxc08"
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 As Integer
Dim a(1000), c(10) As Integer
Dim b(10) As Variant

Private Sub Form_Load()
cxc08.Left = (Screen.Width - Width) / 2
cxc08.Top = (Screen.Height - Height) / 2
i = 0
a(0) = 6: a(1) = 15: a(2) = 16: a(3) = 17: a(4) = 18: a(5) = 19: a(6) = 21: a(7) = 22
a(8) = 7: a(9) = 15: a(10) = 16: a(11) = 17: a(12) = 18: a(13) = 19: a(14) = 20: a(15) = 22
a(16) = 6: a(17) = 15: a(18) = 16: a(19) = 17: a(20) = 18: a(21) = 19: a(22) = 21: a(23) = 22
a(24) = 7: a(25) = 15: a(26) = 16: a(27) = 17: a(28) = 18: a(29) = 19: a(30) = 20: a(31) = 22

a(32) = 6: a(33) = 15: a(34) = 16: a(35) = 17: a(36) = 18: a(37) = 19: a(38) = 21: a(39) = 22
a(40) = 7: a(41) = 15: a(42) = 16: a(43) = 17: a(44) = 18: a(45) = 19: a(46) = 20: a(47) = 22
a(48) = 6: a(49) = 15: a(50) = 16: a(51) = 17: a(52) = 18: a(53) = 19: a(54) = 21: a(55) = 22
a(56) = 7: a(57) = 15: a(58) = 16: a(59) = 17: a(60) = 18: a(61) = 19: a(62) = 20: a(63) = 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 ("快速排序(递增)自动运行显示")
List1.AddItem ("quicksort(int low,int high)")
List1.AddItem ("{")
List1.AddItem ("int pivotpos;")
List1.AddItem ("if(low<high){")
List1.AddItem ("pivotpos=partition(low,high);")
List1.AddItem ("quicksort(low,pivotpos-1);")
List1.AddItem ("quicksort(pivotpos+1,high);")
List1.AddItem ("}")
List1.AddItem ("}")
List1.AddItem ("/***********************************/")
List1.AddItem ("int partition(int i,int j)")
List1.AddItem ("{")
List1.AddItem ("rectype pivot;")
List1.AddItem ("pivot.key=r[i].key;")
List1.AddItem ("while(i<j){")
List1.AddItem ("while((i<j)&&(r[j].key>=pivot.key)) j--;")
List1.AddItem ("if(i<j) r[i++].key=r[j].key;")
List1.AddItem ("while((i<j)&&(r[i].key<=pivot.key)) i++;")
List1.AddItem ("if (i<j) r[j--]=r[i];")
List1.AddItem ("}")
List1.AddItem ("r[i].key=pivot.key;")
List1.AddItem ("return i;")
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 Label13_Click(Index As Integer)
Dim textstr As String
Call QuickSort(b, 1, 10, 1)
For i = 1 To 10
textstr = textstr + Str$(b(i)) + Space(1)
List3.AddItem "第" + Str$(i + 1) + "趟:" + textstr
Next i
End Sub

Private Sub Label14_Click(Index As Integer)
Dim textstr As String
Call QuickSort(b, 1, 10, 0)
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()
cxc09.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



Private Sub Label9_Click()
cxc08.Hide
cxc02.Show
End Sub

Sub QuickSort(s(), L, R, flag)
Dim i, j, X, TEMP, gi

    i = L
    j = R
    X = s((L + R) / 2)
        
    While (i <= j)
    If flag = 0 Then
        While (s(i) < X And i < R)
            i = i + 1
        Wend
        While (X < s(j) And j > L)
            j = j - 1
        Wend
        If (i <= j) Then
            TEMP = s(i)
            s(i) = s(j)
            s(j) = TEMP
            i = i + 1
            j = j - 1
        End If
       ElseIf flag = 1 Then
        While (s(i) > X And i < R)
            i = i + 1
        Wend
        While (X > s(j) And j > L)
            j = j - 1
        Wend
        If (i <= j) Then
            TEMP = s(i)
            s(i) = s(j)
            s(j) = TEMP
            i = i + 1
            j = j - 1
        End If
      End If
        gi = gi + 1
    Wend

    If (L < j) Then Call QuickSort(s(), L, j, flag)
    If (i < R) Then Call QuickSort(s(), i, R, flag)

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 + -