第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

VBA數(shù)組排序函數(shù)?

VBA數(shù)組排序函數(shù)?

VBA數(shù)組排序函數(shù)?我正在為VBA中的數(shù)組尋找一個(gè)合適的排序?qū)崿F(xiàn)。最好是速戰(zhàn)速?zèng)Q?;蛉魏纹渌判蛩惴ǔ伺菖莼蚝喜⒅猓妥銐蛄?。請(qǐng)注意,這是與MSProject 2003一起使用的,因此應(yīng)該避免使用任何Excel本機(jī)函數(shù)和任何與.NET相關(guān)的內(nèi)容。
查看完整描述

3 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

我將“快速排序”算法轉(zhuǎn)換為VBA,如果其他人想要的話。

我對(duì)其進(jìn)行了優(yōu)化,以便在Int/Longs數(shù)組上運(yùn)行,但將其轉(zhuǎn)換為對(duì)任意可比較元素工作的方法應(yīng)該非常簡(jiǎn)單。

Private Sub QuickSort(ByRef a() As Long, ByVal l As Long, ByVal r As Long)
    Dim M As Long, i As Long, j As Long, v As Long
    M = 4

    If ((r - l) > M) Then
        i = (r + l) / 2
        If (a(l) > a(i)) Then swap a, l, i '// Tri-Median Methode!'
        If (a(l) > a(r)) Then swap a, l, r        If (a(i) > a(r)) Then swap a, i, r

        j = r - 1
        swap a, i, j
        i = l
        v = a(j)
        Do
            Do: i = i + 1: Loop While (a(i) < v)
            Do: j = j - 1: Loop While (a(j) > v)
            If (j < i) Then Exit Do
            swap a, i, j        Loop
        swap a, i, r - 1
        QuickSort a, l, j
        QuickSort a, i + 1, r    End IfEnd SubPrivate Sub swap(ByRef a() As Long, ByVal i As Long, ByVal j As Long)
    Dim T As Long
    T = a(i)
    a(i) = a(j)
    a(j) = TEnd SubPrivate Sub InsertionSort(ByRef a(), ByVal lo0 As Long, ByVal hi0 As Long)
    Dim i As Long, j As Long, v As Long

    For i = lo0 + 1 To hi0
        v = a(i)
        j = i        Do While j > lo0            If Not a(j - 1) > v Then Exit Do
            a(j) = a(j - 1)
            j = j - 1
        Loop
        a(j) = v    Next iEnd SubPublic Sub sort(ByRef a() As Long)
    QuickSort a, LBound(a), UBound(a)
    InsertionSort a, LBound(a), UBound(a)End Sub


查看完整回答
反對(duì) 回復(fù) 2019-07-01
?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個(gè)贊

解釋在德文中,代碼是一個(gè)經(jīng)過良好測(cè)試的就地實(shí)現(xiàn):

Private Sub QuickSort(ByRef Field() As String, ByVal LB As Long, ByVal UB As Long)
    Dim P1 As Long, P2 As Long, Ref As String, TEMP As String

    P1 = LB
    P2 = UB
    Ref = Field((P1 + P2) / 2)

    Do
        Do While (Field(P1) < Ref)
            P1 = P1 + 1
        Loop

        Do While (Field(P2) > Ref)
            P2 = P2 - 1
        Loop

        If P1 <= P2 Then
            TEMP = Field(P1)
            Field(P1) = Field(P2)
            Field(P2) = TEMP

            P1 = P1 + 1
            P2 = P2 - 1
        End If
    Loop Until (P1 > P2)

    If LB < P2 Then Call QuickSort(Field, LB, P2)
    If P1 < UB Then Call QuickSort(Field, P1, UB)End Sub

像這樣被引用:

Call QuickSort(MyArray, LBound(MyArray), UBound(MyArray))


查看完整回答
反對(duì) 回復(fù) 2019-07-01
  • 3 回答
  • 0 關(guān)注
  • 1653 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)