More accurate asp bubble sorting _ javascript skills
Source: Internet
Author: User
More correct asp bubble sorting the code found on the Internet.
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
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
Error ......
Test it.
S = "11,3, 1"
S = sort (split (s ,","))
For I = 0 to ubound (s)
Response. write s (I )&"
"
Next
The printed 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
The difference is in a clng ()
But it is funny that some arrays can be correctly arranged using the wrong sort function.
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.