asp下常用的排序算法

2019-10-16 07:54:40来源:爱站网 阅读 ()

新老客户大回馈,云服务器低至5折

在asp中我们经常会需要对一些数据进行排序,那么你知道asp下常用的排序算法有哪些吗?我们又该如何运用它们,那么今天就让小编为大家详细介绍一下吧。

<%

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下常用的排序算法的内容,如果大家想了解更多相关内容,请持续关注本站,本站小编将在第一时间为大家带来更好的经典内容。


原文链接:https://js.aizhan.com/develop/asp/9522.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:利用ASP新方法生成html

下一篇:防止垃圾留言的asp代码