ASP : Sort Array
การจัดเรียง Array นะครับ
MyArray=Array(25,14,20,45,25,4,1,31,22,7)
Sort: Ascending
<%MyArray=Array(25,14,20,45,25,4,1,31,22,7)
max=ubound(MyArray)
For i=0 to max
For j=i+1 to max
if MyArray(i)>MyArray(j) then
TemporalVariable=MyArray(i)
MyArray(i)=MyArray(j)
MyArray(j)=TemporalVariable
end if
next
next
For i=0 to max
Response.Write(MyArray(i) & ",")
next
%>
ผลลัพท์
1,4,7,14,20,22,25,25,31,45
Response.Write(MyArray(i) & ",")
next
%>
ผลลัพท์
1,4,7,14,20,22,25,25,31,45
Sort: Descending
<%
MyArray=Array("John","Peter","Anna","Alberto","George","Unai")
<%
MyArray=Array("John","Peter","Anna","Alberto","George","Unai")
max=ubound(MyArray)
For i=0 to max
For j=i+1 to max
if MyArray(i) then
TemporalVariable=MyArray(i)
MyArray(i)=MyArray(j)
MyArray(j)=TemporalVariable
end if
next
next
For i=0 to max
Response.Write(MyArray(i) & ",")
next
%>
Response.Write(MyArray(i) & ",")
next
%>
ผลลัพท์
Unai,Peter,John,George,Anna,Alberto
มาเป็นเพื่อนกันครับ บนช่องทาง Social ด้านล่างนี้ครับ
--------------------------► LINE@ : @siamfocus.com
► Facebook : fanpage.siamfocus
► Twitter (X) : siamfocus
► Linkedin : taam-siamfocus
► Instagram : iamtaam
► Youtube : SiAMFOCUS
► Tiktok : @taamsiamfocus
--------------------------