排序 <% DimaData CallResponseArray(aData,"原来顺序") Fori=0Tobound-1 SelectSort=a_Data Fori=0Tobound-1 QuickSort=a_Data Fori=1Tobound '输出数组 %>
aData=Array(3,2,4,1,6,0)
CallResponseArray(SelectSort(aData),"选择排序")
CallResponseArray(QuickSort(aData),"快速排序")
CallResponseArray(InsertSort(aData),"插入排序")
CallResponseArray(BubbleSort(aData),"冒泡排序")
'选择排序
FunctionSelectSort(a_Data)
Dimi,j,k
Dimbound,t
bound=UBound(a_Data)
k=i
Forj=i+1Tobound
Ifa_Data(k)>a_Data(j)Then
k=j
EndIf
Next
t=a_Data(i)
a_Data(i)=a_Data(k)
a_Data(k)=t
Next
EndFunction
'快速排序
FunctionQuickSort(a_Data)
Dimi,j
Dimbound,t
bound=UBound(a_Data)
Forj=i+1Tobound
Ifa_Data(i)>a_Data(j)Then
t=a_Data(i)
a_Data(i)=a_Data(j)
a_Data(j)=t
EndIf
Next
Next
EndFunction
'冒泡排序
FunctionBubbleSort(a_Data)
Dimbound
bound=UBound(a_Data)
DimbSorted,i,t
bSorted=False
DoWhilebound>0AndbSorted=False
bSorted=True
Fori=0Tobound-1
Ifa_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
EndIf
Next
bound=bound-1
Loop
BubbleSort=a_Data
EndFunction
'插入排序
FunctionInsertSort(a_Data)
Dimbound
bound=UBound(a_Data)
Dimi,j,t
t=a_Data(i)
j=i
DoWhilet<a_Data(j-1)Andj>0
a_Data(j)=a_Data(j-1)
j=j-1
Loop
a_Data(j)=t
Next
InsertSort=a_Data
EndFunction
SubResponseArray(a_Data,str)
Dims
s=""
Response.Write"<b>"&str&":</b>"
Fori=0ToUBound(a_Data)
s=s&a_Data(i)&","
Next
s=Left(s,Len(s)-1)
Response.Writes
Response.Write"<hr>"
EndSub
常用的几种asp排序方法介绍
80酷酷网 80kuku.com