这是一个简单的例子: dim ar,i,j,vTemp ar = array(狗,猫,鸟,猴子) response.write"排序前:< BR>" for i = 0 to ubound(ar) 回复.write ar(i)& < BR>" next for i = 0 to ubound(ar)-1 for j = i + 1到ubound(ar) 如果ar(j)< = ar(i)那么 vTemp = ar(j) ar( j)= ar(i) ar(i)= vTemp 结束如果 next next response.write"排序后:< BR>" for i = 0 to ubound(ar) response.write ar (i)& < BR>" next 要对数字进行排序,请更改if ar(j)< = ar(i)then toif cdbl(ar(j))< = cdbl(ar(i))then,或cint,clng等,具体取决于数字的类型 你正在整理。 HTH, Bob Barrows Hello, Can anyone help out with a bubble sort for strings using ASP? I have a textfile of words id like to sort and count. Thanks in advance for any help. Gram. 解决方案 Here''s a quick example:dim ar, i , j, vTempar=array(dog,cat,bird,monkey)response.write "Before Sort:<BR>"for i = 0 to ubound(ar)response.write ar(i) & "<BR>"nextfor i=0 to ubound(ar)-1for j = i+1 to ubound(ar)if ar(j) <= ar(i) thenvTemp = ar(j)ar(j) = ar(i)ar(i) = vTempend ifnextnextresponse.write "After Sort:<BR>"for i = 0 to ubound(ar)response.write ar(i) & "<BR>"next To sort numbers, change "if ar(j) <= ar(i) then" to "if cdbl(ar(j)) <=cdbl(ar(i)) then", or cint, clng, etc., depending on what type of numbersyou are sorting.HTH,Bob Barrows 这篇关于字符串冒泡排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 16:52