2010年10月18日 星期一

插入排序

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a() = {9, 1, 8, 7, 6, 5, 4, 10, 3, 2}
        For i = 1 To a.Length - 1
            Dim p = a(i)
            Dim j = 0
            While a(j) < p
                j = j + 1
            End While
            For k = i To j + 1 Step -1
                a(k) = a(k - 1)
            Next
            a(j) = p
        Next
        End
    End Sub

沒有留言: