下面请欣赏舞蹈:shell排序 (踢踏舞跳得真不错)

http://v.youku.com/v_show/id_XMjU4NTcwMDIw.html

[b][flash=480,400]http://player.youku.com/player.php/sid/XMjU4NTcwMDIw/v.swf[/flash][/b]


[b][flv=480,400][b][flash=480,400]http://player.youku.com/player.php/sid/XMjU4NTcwMDIw/v.swf[/flash] [/b][/flv]
[/b]


看完了吧,再看一篇,,发现这个都是倒序向前比较,步长是span。

自己强化学习一下:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()
        ListBox2.Items.Clear()
        Dim i, j, span As Short
        Dim a(10) As String, temp As String
        Randomize()

        For i = 0 To a.Length - 1
            a(i) = Int(10 * Rnd())
            ListBox1.Items.Add(a(i))
        Next
        span = a.Length \ 2
        Do While span > 0
            For i = span To a.Length - 1
                For j = i - span To 0 Step -span
                    If a(j) <= a(j + span) Then Exit For
                    temp = a(j)
                    a(j) = a(j + span)
                    a(j + span) = temp
                Next
            Next
            span = span \ 2
        Loop
        For i = 0 To a.Length - 1
            ListBox2.Items.Add(a(i))
        Next
    End Sub
End Class

下面请欣赏舞蹈:shell排序 (踢踏舞跳得真不错)_第1张图片








你可能感兴趣的:(下面请欣赏舞蹈:shell排序 (踢踏舞跳得真不错))