- ©«¤l
- 1018
- ¥DÃD
- 15
- ºëµØ
- 0
- ¿n¤À
- 1058
- ÂI¦W
- 0
- §@·~¨t²Î
- win7 32bit
- ³nÅ骩¥»
- Office 2016 64-bit
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ®ç¶é
- µù¥U®É¶¡
- 2012-5-9
- ³Ì«áµn¿ý
- 2022-9-28
|
¦^´_ 1# s13030029 - Public Sub MergeSort(array_in, begin, final, Optional array_temp)
- 'array_in: 1 dimension array
- If begin >= final Then Exit Sub
- If IsMissing(array_temp) Then
- ReDim array_temp(LBound(array_in) To UBound(array_in))
- End If
- Dim mid
- mid = (begin + final) \ 2
- MergeSort array_in, begin, mid, array_temp
- MergeSort array_in, mid + 1, final, array_temp
- Merge array_in, begin, mid, final, array_temp
- End Sub
- Private Sub Merge(ar, begin, mid, final, temp)
- Dim left: left = begin
- Dim right: right = mid + 1
- Dim i: i = begin
- Do
- If left > mid Then Exit Do
- If right > final Then Exit Do
- If CmprOperator(ar(left), ar(right)) Then
- temp(i) = ar(left)
- left = left + 1
- Else
- temp(i) = ar(right)
- right = right + 1
- End If
- i = i + 1
- Loop
- For n = left To mid
- temp(i) = ar(n)
- i = i + 1
- Next
- For n = right To final
- temp(i) = ar(n)
- i = i + 1
- Next
- For n = begin To final
- ar(n) = temp(n)
- Next
- End Sub
- Private Function CmprOperator(a, b) As Boolean
- If Len(a) <= Len(b) Then
- CmprOperator = True
- Else
- CmprOperator = False
- End If
- End Function
½Æ»s¥N½X- Public Sub test()
- Dim ar
- ar = Array("½Ð°Ý", "VBA", "¦³¿ìªk", "¨Ì", "¤¤¤å¦r¼Æ¦h¹è", "°µ", "±Æ§Ç", "¶Ü")
- MergeSort ar, LBound(ar), UBound(ar)
- Debug.Print Join(ar, ",")
- ' Output>> ¨Ì,°µ,¶Ü,½Ð°Ý,±Æ§Ç,VBA,¦³¿ìªk,¤¤¤å¦r¼Æ¦h¹è
- End Sub
½Æ»s¥N½X |
|