How to modify the correct asp bubble sort? Many friends have been troubled by this problem, so let’s take a look at the correct modification of Asp bubble sorting now. Friends who don’t know yet, please refer to it.
The code I searched online is the same as this one
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
There is an error. . . . . .
Just test it out
s="11,3,1"
s=sort(split(s,","))
for i=0 to ubund(s)
response.write s(i) & "<br>"
next
The print result is
1
11
3
The correct function is:
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
Just one clng()
The above is the correct way to modify asp bubble sort, but what's funny is that some arrays can be sorted correctly with the wrong sort function.