<%
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
%>
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,排序
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“asp下几种常用排序算法”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。