<% Dim aData Call ResponseArray(aData, “原来顺序”) For i = 0 To bound-1 SelectSort = a_Data For i = 0 To bound-1 QuickSort = a_Data For i = 1 To bound 输出数组 %>
aData = Array(3,2,4,1,6,0)
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)
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
End Function
快速排序
Function QuickSort(a_Data)
Dim i, j
Dim bound, t
bound = UBound(a_Data)
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
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
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) _asp技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 几种常用排序算法(asp) _asp技巧
相关推荐
-      ASP基础教程:其它的ASP常用组件
-      ASP基础教程:学习ASP中子程序的应用
-      ASP基础教程之ASP程序对Cookie的处理
-      ASP基础教程之ASP AdRotator组件的使用
-      ADO初学者教程:ADO 通过GetString()加速脚本
-      ASP技巧实例:几行代码解决防止表单重复提交
-      ASP常见数学函数 Abs Atn Cos 等详细详解[ 来源:网页教学网 | 作者: | 时间:2007-09-12 10:57:29 | 收藏本文 ] 【大 中 小】【名称】
-      ASP基础教程之ASP AdRotator 组件的使用