【VB开源代码栏目提醒】:网学会员,鉴于大家对VB开源代码十分关注,论文会员在此为大家搜集整理了“Ex5_16.frm”一文,供大家参考学习!
VERSION 5.00
Begin VB.Form Ex5_16
Caption = "Form1"
ClientHeight = 2655
ClientLeft = 60
ClientTop = 450
ClientWidth = 4365
LinkTopic = "Form1"
ScaleHeight = 2655
ScaleWidth = 4365
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "选择排序"
Height = 375
Left = 2280
TabIndex = 5
Top = 2040
Width = 1215
End
Begin VB.TextBox Text2
Height = 375
Left = 240
TabIndex = 4
Top = 1440
Width = 3735
End
Begin VB.CommandButton Command1
Caption = "冒泡排序"
Height = 375
Left = 600
TabIndex = 2
Top = 2040
Width = 1215
End
Begin VB.TextBox Text1
Height = 375
Left = 240
TabIndex = 1
Top = 600
Width = 3735
End
Begin
VB.Label Label2
Caption = "数组各元素按从小到大的排序顺序为"
Height = 255
Left = 360
TabIndex = 3
Top = 1080
Width = 3135
End
Begin VB.Label Label1
Caption = "请输入数组元素的值,用逗号分隔"
Height = 255
Left = 360
TabIndex = 0
Top = 240
Width = 3135
End
End
Attribute VB_Name = "Ex5_16"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Sub BubbleSort(a() As String)
Dim i As Integer, j As Integer, n As Integer, t As String
n = UBound(a)
For j = 1 To n
For i = 0 To n - j
If CInt(a(i)) > CInt(a(i + 1)) Then '相邻的数比较并调换顺序
t = a(i) 'T为中间变量
a(i) = a(i + 1)
a(i + 1) = t
End If
Next i
Next j
End Sub
Private Sub Command1_Click()
Dim str() As String '定义数组
Dim i As Integer
str() = Split(Text1.Text, ",") '为数组str赋值
Call BubbleSort(str)
Text2.Text = Join(str, ",")
End Sub
Sub SelectSort(a() As String)
Dim i As Integer, j As Integer, k As Integer, n As Integer, t As String
n = UBound(a)
For i = 0 To n - 1
k = i
For j = i + 1 To n
If CInt(a(j)) < CInt(a(k)) Then k = j
Next j
If k <> i Then
t = a(k)
a(k) = a(i)
a(i) = t
End If
Next i
End Sub
Private Sub Command2_Click()
Dim str() As String '定义数组
Dim i As Integer
str() = Split(Text1.Text, ",") '为数组str赋值
Call BubbleSort(str)
Text2.Text = Join(str, ",")
End Sub