2009年4月30日 星期四

Shell Sort

image

'Shell Sort 謝耳排序
Public Class Form1
    Dim a() = {90, 95, 92, 93, 94}
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i
        Dim str1 = ""
        Dim d = 5 \ 2

        While d <> 0
            Dim isChange As Boolean = False
            For i = 0 To 4 - d
                If a(i) > a(i + d) Then
                    Dim t = a(i)
                    a(i) = a(i + d)
                    a(i + d) = t
                    isChange = True
                End If
            Next
            If isChange = False Then
                d = d \ 2
            End If
        End While

        For i = 0 To 4
            str1 = str1 & a(i) & Space(3)
        Next
        MsgBox(str1)
    End Sub
End Class

沒有留言:

張貼留言