回 帖 发 新 帖 刷新版面

主题:[讨论]这么简单的程序也会有错

帮忙看下这个程序,我还不信他的:
一个vbscript程序:
<%
const N=9
dim i,j,temp
redim array1(N)
for i=0 to 9
    array1(i)=9-i
next
response.write "输入数组中的内容为:"&"<br>"
for i=0 to N
   response.write "array1("&i&")="&array1(i)&"<br>" 
next   
for i=0 to N
    for j=i to N-i
        if j>=N then exit for 
    else
           if array1(j)<array1(j+1) then
              temp=array1(j):array1(j)=array1(j+1):array1(j+1)=temp
           end if
        end if
    next
next
response.write "排序后的结果为:"&"<br>"
for i=0 to N
  response.write "array1("&i&")="&array(i)&"<br>"            
next  
 
%>

回复列表 (共1个回复)

沙发

<%
const N=9
dim i,j,temp
redim array1(N)
for i=0 to 9
    array1(i)=9-i
next
response.write "输入数组中的内容为:"&"<br>"
for i=0 to N
   response.write "array1("&i&")="&array1(i)&"<br>" 
next   
for i=0 to N
    for j=i to N-i
        if j>=N then exit for 
       
           if array1(j)<array1(j+1) then
              temp=array1(j)
              array1(j)=array1(j+1)
              array1(j+1)=temp
           end if
    next
next

response.write "排序后的结果为:"&"<br>"
for i=0 to N
  response.write "array1("&i&")="&array1(i)&"<br>"            
next  
%>
算法没错,粗心而已,原文中多了个else和end if ,exit for是不需要end if结尾的
response.write "array1("&i&")="&array(i)&"<br>"            
后面的"&array(i)&"应该是"&array1(i)&" 少个"1"
顺便说下 这样排序似乎太累了点,可以有更简单的办法,如果数组大了的话,你的程序就慢了,呵呵

我来回复

您尚未登录,请登录后再回复。点此登录或注册