打印本文 打印本文  关闭窗口 关闭窗口  
Asp数组冒泡排序函数
作者:佚名  文章来源:NET  点击数  更新时间:2006/2/22 2:04:02  文章录入:admin  责任编辑:admin

Function Sort(ary)
Dim KeepChecking,I,FirstValue,SecondValue
 KeepChecking = TRUE
Do Until KeepChecking = FALSE
 KeepChecking = FALSE
 For I = 0 to UBound(ary)
  If I = UBound(ary) Then Exit For
   If ary(I) > ary(I+1) Then
    FirstValue = ary(I)
    SecondValue = ary(I+1)
    ary(I) = SecondValue
    ary(I+1) = FirstValue
    KeepChecking = TRUE
   End If
 Next
Loop
 Sort = ary
End Function
 
dim ID,ArrayID,Myarray,M
ID="55,48,78,10,90"
ArrayID=split(ID,",")
Myarray=Sort(ArrayID)
'排序测试
For M=0 To Ubound(Myarray)
      Response.Write Myarray(M) & "<br>" & vbCRLF
Next
 
'当然也可以用下面的,
Dim Myarray
Myarray=Array(12,10,25,78,45)
Myarray=Sort(ArrayID)
'排序测试
For M=0 To Ubound(Myarray)
      Response.Write Myarray(M) & "<br>" & vbCRLF
Next
'排序测试
打印本文 打印本文  关闭窗口 关闭窗口