你的位置:HBcms宏博内容管理系统 建站经验 正文
内容搜索
热门内容
  1. 网站logo在线设计,免..
  2. 域名解析文件hosts文件..
  3. 教你如何做网线接头:..
  4. qq怎么截图?如何在qq..
  5. 雅虎yahoo邮箱smtp和p..
  6. 新注册126邮箱或163邮..
  7. 幻灯片式的网页图片滚..
  8. 做网站怎么赚钱?什么..
  9. com域名和cn域名net域..
  10. Google支付系统(Googl..
推荐内容
  1. 做一个商业网站要多少..
  2. 国外服务器租用(国外..
  3. 深圳做网站的公司!=深..
  4. 网络原创投稿,转载精..
  5. 美国服务器租赁Window..
  6. 699元的美国服务器出租..
  7. 添加友情链接,速度别..
  8. “原始人”卷款潜逃事..
  9. 设置Godaddy支持zend ..
  10. 网页设计中常用的CSS命..
几种常用排序算法(asp)
  • 原作者:purefei 添加时间:2007-09-27 发表时间:2007-09-27 人气:101
  • <%

    Dim aData
    aData = Array(3,2,4,1,6,0)

    Call ResponseArray(aData, "原来顺序")
    Call ResponseArray(SelectSort(aData), "选择排序")
    Call ResponseArray(QuickSort(aData), "快速排序")
    Call ResponseArray(InsertSort(aData), "插入排序")
    Call ResponseArray(BubbleSort(aData), "冒泡排序")


    '选择排序
    Function SelectSort(a_Data)
        Dim i, j, k
        Dim bound, t
        bound = UBound(a_Data)

        For i = 0 To bound-1
            k = i
            For j = i+1 To bound
                If a_Data(k) > a_Data(j) Then
                    k = j
                End If
            Next
            t = a_Data(i)
            a_Data(i) = a_Data(k)
            a_Data(k) = t
        Next

        SelectSort = a_Data
    End Function


    '快速排序
    Function QuickSort(a_Data)
        Dim i, j
        Dim bound, t
        bound = UBound(a_Data)

        For i = 0 To bound-1
            For j = i+1 To bound
                If a_Data(i) > a_Data(j) Then
                    t = a_Data(i)
                    a_Data(i) = a_Data(j)
                    a_Data(j) = t
                End If
            Next
        Next

        QuickSort = a_Data
    End Function


    '冒泡排序
    Function BubbleSort(a_Data)
        Dim bound
        bound = UBound(a_Data)
        Dim bSorted, i, t
        bSorted = False
       
        Do While bound > 0 And bSorted = False
           
            bSorted = True
            For i = 0 To bound-1
                If a_Data(i) > a_Data(i+1) Then
                    t = a_Data(i)
                    a_Data(i) = a_Data(i+1)
                    a_Data(i+1) = t
                    bSorted = False
                End If
            Next
            bound = bound - 1
        Loop
       
        BubbleSort = a_Data
    End Function


    '插入排序
    Function InsertSort(a_Data)
        Dim bound
        bound = UBound(a_Data)
        Dim i, j, t

        For i = 1 To bound
            t = a_Data(i)
            j = i
            Do While t<a_Data(j-1) And j>0
                a_Data(j) = a_Data(j-1)
                j = j - 1
            Loop
            a_Data(j) = t
        Next
           
        InsertSort = a_Data
    End Function

    '输出数组
    Sub ResponseArray(a_Data, str)
        Dim s
        s = ""
        Response.Write "<b>" & str & ":</b>"
        For i = 0 To UBound(a_Data)
            s = s & a_Data(i) & ","
        Next
        s = Left(s, Len(s)-1)
        Response.Write s
        Response.Write "<hr>"
    End Sub

    %>

  • 点这里复制本页地址发送给您QQ/MSN上的好友
  • 相关文章
  • 相关评论
  • 本文章所属分类:首页 建站经验