数组排序
作者:cmscn 日期:2009-08-13
<%
server.scripttimeout=300
count=100
Arr=count-1
dim nums()
response.write "原数组:<br />"
for i=0 to Arr
ReDim Preserve nums(i)
randomize()
num=(cint(rnd()*9999))
nums(i)=num
response.write num&" "
if (i+1) mod 20 =0 then response.write "<br />"
next
'计算最大值和最小值
max=nums(0)
min=nums(0)
for j=1 to Arr
if nums(j)>max then max=nums(j)
if nums(j)<min then min=nums(j)
next
'由小到大排序
num_m=0
time1=timer
for j=0 to Arr
for i=0 to Arr-1
if nums(i)>nums(i+1) then
num_m=nums(i+1)
nums(i+1)=nums(i)
nums(i)=num_m
complete=false
end if
next
next
'排序完成
response.write "<br />排序后:<br />"
for k=0 to Arr
response.write nums(k)&" "
if (k+1) mod 20 =0 then response.write "<br />"
next
response.write "<br />数组共有"&color(count)&"个数,最大值:"&color(max)&",最小值:"&color(min)&";<br />"
function color(str)
color="<font color=""red"">"&str&"</font>"
end function
%>
评论: 0 | 引用: 0 | 查看次数: 426
发表评论