国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 辦公 > Excel > 正文

VBA數(shù)組的升序、降序

2019-10-25 20:24:09
字體:
供稿:網(wǎng)友

   ①升序排序的VBA數(shù)組

  Function UP(x()) As Variant()

  Dim i As Integer, j As Integer, a, d()

  ReDim sx(LBound(x) To UBound(x)), d(LBound(x) To UBound(x))

  d = x

  If LBound(x) = UBound(x) Then

  sx = d

  Exit Function

  End If

  For i = LBound(x) To UBound(x) - 1

  For j = i + 1 To UBound(x)

  If d(j) < d(i) Then

  a = d(j): d(j) = d(i): d(i) = a

  End If

  Next

  Next

  sx = d

  End Function

  ②VBA數(shù)組的降序排序

  Function Down(x()) As Variant()

  Dim i As Integer, j As Integer, a, d()

  ReDim sx(LBound(x) To UBound(x)), d(LBound(x) To UBound(x))

  d = x

  If LBound(x) = UBound(x) Then

  sx = d

  Exit Function

  End If

  For i = LBound(x) To UBound(x) - 1

  For j = i + 1 To UBound(x)

  If d(j) > d(i) Then

  a = d(j): d(j) = d(i): d(i) = a

  End If

  Next

  Next

  sx = d

  End Function

  ③針對(duì)中文字符的數(shù)組排序

  如果你想針對(duì)字符數(shù)組進(jìn)行排序,可參考如下的代碼

  Sub Start() Dim arr() As Variant arr = Array("大", "眾", "計(jì)", "算", "機(jī)", "學(xué)", "習(xí)", "網(wǎng)")

  QuickSort2 arr(), 0, UBound(arr) Dim s As String For I = 1 To UBound(arr) s = s & arr(I) & " | " Next MsgBox s

  End Sub Sub QuickSort2(MyArray() As Variant, L, R) Dim tp tp = 1

  Dim I, J, X, Y I = L J = R X = MyArray((L + R) / 2) While (I <= J) While (StrComp(MyArray(I), X, tp) < 0 And I < R) I = I + 1 Wend While (StrComp(X, MyArray(J), tp) < 0 And J > L) J = J - 1 Wend If (I <= J) Then Y = MyArray(I) MyArray(I) = MyArray(J) MyArray(J) = Y I = I + 1 J = J - 1 End If gIterations = gIterations + 1 Wend

  If (L < J) Then Call QuickSort2(MyArray(), L, J) If (I < R) Then Call QuickSort2(MyArray(), I, R)

  End Sub


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 旬阳县| 宣化县| 濉溪县| 望城县| 茂名市| 兖州市| 鹿泉市| 美姑县| 吐鲁番市| 故城县| 无为县| 郧西县| 贡嘎县| 天峻县| 民和| 韩城市| 桂平市| 潜山县| 永川市| 祁东县| 大足县| 安化县| 科技| 航空| 罗定市| 遂宁市| 桃园市| 铁岭县| 海阳市| 行唐县| 凤凰县| 交口县| 锦屏县| 彭泽县| 榆树市| 涞源县| 公安县| 公安县| 广丰县| 宁远县| 溆浦县|