| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1799 人关注过本帖
标题:将字符串 8945271603 按 0123456789 输出
只看楼主 加入收藏
kingfangden
Rank: 4
来 自:深圳
等 级:贵宾
威 望:11
帖 子:57
专家分:279
注 册:2013-12-20
结帖率:33.33%
收藏
已结贴  问题点数:5 回复次数:1 
将字符串 8945271603 按 0123456789 输出
求高手赐教。帮写一算法。将字符串8945271603按0123456789输出。多谢!
搜索更多相关主题的帖子: 字符串 
2014-11-02 18:22
ysf0181
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
收藏
得分:5 
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

ASP讨论QQ群:251346273
2014-11-03 08:51
快速回复:将字符串 8945271603 按 0123456789 输出
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069731 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved