前一篇介绍了“asp双向冒泡排序法”,今天介绍一下“asp双向选择排序法”,代码如下:
<% function cocktailSort_selectionSort(byval b) '鸡尾酒排序,双向选择排序 len2=ubound(b) for i=0 to len2\2 min=i max=len2-i for j=i+1 to len2-i if b(min)>b(j) then min=j end if next t=b(min) b(min)=b(i) b(i)=t for j=i to len2-i-1 if b(max)<b(j) then max=j end if next t=b(max) b(max)=b(len2-i) b(len2-i)=t next cocktailSort_selectionSort = b end function a=array(49,38,65,97,76,13,27) response.write "初始顺序: " for i=0 to ubound(a) response.write a(i)&" " next response.write "<hr>" a = cocktailSort_selectionSort(a) response.write "最终排序结果:" for i=0 to ubound(a) response.write a(i)&" " next %>(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)
函数cocktailSort_selectionSort(byval b)就是双向选择排序法。
原创文章,转载请注明来源(www.aspbc.com),谢谢。