更正确的asp冒泡排序
时间:2024-04-22 13:04:10
网上搜到的代码,千篇一律是这个
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
存在错误。。。。。。
测试一下就知道
s="11,3,1"
s=sort(split(s,","))
for i=0 to ubound(s)
response.write s(i) & "<br>"
next
打印结果是
1
11
3
正确的function是:
function sort(ary)
ck=true
do Until ck = false
ck=false
For f = 0 to UBound(ary) -1
if clng(ary(f))>clng(ary(f+1)) then
v1=clng(ary(f))
v2=clng(ary(f+1))
ary(f)=v2
ary(f+1)=v1
ck=true
end if
next
loop
sort=ary
end function
就差在一个clng()
但好笑的是,有些数组,用那个错误的sort函数是可以排正确的。
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
网页设计中的层次感
![](https://img.aspxhome.com/file/UploadPic/200711/5/2007115182428922s.png)
数据库自动化技术弥补数据库DBA短缺难题
MySQL字符串索引更合理的创建规则讨论
![](https://img.aspxhome.com/file/2023/0/68110_0s.png)
详解Python_shutil模块
python编写朴素贝叶斯用于文本分类
![](https://img.aspxhome.com/file/2023/3/98323_0s.jpg)
谨慎使用PHP的引用原因分析
python中arrow库用法大全
![](https://img.aspxhome.com/file/2023/4/104804_0s.png)
关于Python dict存中文字符dumps()的问题
![](https://img.aspxhome.com/file/2023/7/79507_0s.png)
sqlserver 修改列名及表名的sql语句
jmeter正则表达式的使用
![](https://img.aspxhome.com/file/2023/2/86872_0s.png)
Python学习之线程池与GIL全局锁详解
![](https://img.aspxhome.com/file/2023/8/111858_0s.gif)
Python中性能分析利器pyinstrument详细讲解
![](https://img.aspxhome.com/file/2023/9/134639_0s.jpg)
python实现ping命令小程序
![](https://img.aspxhome.com/file/2023/9/75159_0s.png)
解决py2exe打包后,总是多显示一个DOS黑色窗口的问题
大前端时代搞定PC/Mac端开发,我有绝招(收藏版)
![](https://img.aspxhome.com/file/2023/4/117514_0s.png)
Python中PyMySQL的基本操作
python 计算两个列表的相关系数的实现
![](https://img.aspxhome.com/file/2023/9/94159_0s.png)
Python3 集合set入门基础
![](https://img.aspxhome.com/file/2023/2/105342_0s.png)
Python中flatten( )函数及函数用法详解
利用ASP在线维护数据库
![](https://img.aspxhome.com/file/UploadPic/200710/12/20071012135842950s.jpg)