Modify the correct ASP bubble sort _ Application Tips
Source: Internet
Author: User
The code found on the Internet, this is the same
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 are errors ...
Just test it.
S= "11,3,1"
S=sort (Split (S, ","))
For I=0 to UBound (s)
Response.Write S (i) & "<br>"
Next
Print results are
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
On a clng ()
But the funny thing is that some arrays, with that wrong sort function, can be lined up correctly.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service