關於基數排序法radix sort 的演算法

26,59,77,31,51,11,19,42 以基數排序法 遊小而大 經過第一次排序 結果 如可以 由算是解釋 能更進一步晚整呈現 感激

1 個解答

評分
  • DRGO
    Lv 5
    1 0 年前
    最佳解答

    Private Sub Form_Load()

    a = Array(26, 59, 77, 31, 51, 11, 19, 42)

    Dim b() As Integer, n(9) As Integer

    ReDim b(9, UBound(a)) As Integer

    For i = 0 To UBound(a)

    reg% = Right(a(i), 1)

    b(reg, n(reg)) = a(i)

    n(reg) = n(reg) + 1

    Next i

    cont = 0

    For i = 0 To 9

    If n(i) > 0 Then

    For j = 0 To n(i) - 1

    a(cont) = b(i, j)

    Print a(cont);

    cont = cont + 1

    Next j

    End If

    Next i

    For i = 0 To 9: n(i) = 0: Next

    For i = 0 To UBound(a)

    If a(i) > 9 Then reg = Left(a(i), 1) Else reg = 0

    b(reg, n(reg)) = a(i)

    n(reg) = n(reg) + 1

    Next i

    Print ""

    cont = 0

    For i = 0 To 9

    If n(i) > 0 Then

    For j = 0 To n(i) - 1

    a(cont) = b(i, j)

    Print a(cont);

    cont = cont + 1

    Next j

    End If

    Next i

    End Sub

    參考資料: feeling
還有問題?馬上發問,尋求解答。