|
LZ的ASC2 码是冒泡排序,下面这段是选择排序法,感兴趣的可以自己看看。
Private Sub Form_Activate()
Dim str As String, n As Integer, arrayStr() As String, lenth As Integer, fStr As String, compareStr As String, j As Integer, exChange As Integer
str = InputBox("请输入想要排序的字符串")
lenth = Len(str)
For n = 1 To lenth - 1
fStr = fStr + Left(str, 1) + ","
str = Right(str, lenth - n)
Next n
fStr = fStr + Right(str, 1)
arrayStr = Split(fStr, ",")
For n = 0 To UBound(arrayStr)
compareStr = arrayStr(n)
For j = n To UBound(arrayStr)
If (Asc(arrayStr(j)) < Asc(compareStr)) Then
exChange = j
compareStr = arrayStr(j)
arrayStr(exChange) = arrayStr(n)
arrayStr(n) = compareStr
End If
Next j
Next n
For n = 0 To UBound(arrayStr)
Print arrayStr(n)
Next n
End Sub |
|