修改正確的asp冒泡排序
更新時間:2008年01月12日 09:55:50 作者:
修改正確的asp冒泡排序
網(wǎng)上搜到的代碼,千篇一律是這個
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
打印結(jié)果是
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()
但好笑的是,有些數(shù)組,用那個錯誤的sort函數(shù)是可以排正確的。
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
打印結(jié)果是
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()
但好笑的是,有些數(shù)組,用那個錯誤的sort函數(shù)是可以排正確的。
相關(guān)文章
asp 多關(guān)鍵詞搜索的簡單實(shí)現(xiàn)方法
asp搜索兩個以上的詞的實(shí)現(xiàn)方法,簡單的就是利用split,其它的可以參考本站之前更新的文章2008-11-11
asp連接SQL和Access數(shù)據(jù)代碼(asp里的隨機(jī)函數(shù))
asp連接SQL和Access數(shù)據(jù)代碼,asp里的隨機(jī)函數(shù),需要的朋友可以參考下2012-09-09
asp IsValidEmail 驗(yàn)證郵箱地址函數(shù)(email)
驗(yàn)證郵箱很多在js客戶端驗(yàn)證了,但是那樣很容易被人破了,我們在服務(wù)器上用asp進(jìn)行驗(yàn)證的話就應(yīng)該沒有問題了。2010-05-05
GetPaing 函數(shù)之a(chǎn)sp采集函數(shù)中用到的獲取分頁的代碼
GetPaing 函數(shù)之a(chǎn)sp采集函數(shù)中用到的獲取分頁的代碼...2007-09-09
ASP多條件查詢功能實(shí)現(xiàn)代碼(多關(guān)鍵詞查詢)
今天在用asp增加一個多條件查詢,標(biāo)題可以包括多個關(guān)鍵詞,這樣提高匹配,防止內(nèi)容重復(fù)等2014-05-05

