当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

asp鸡尾酒排序法之二“双向选择排序法”

减小字体 增大字体 作者:wangsdong     来源:asp编程网  发布时间:2018-12-30 8:29:32

前一篇介绍了“asp双向冒泡排序法”,今天介绍一下“asp双向选择排序法”,代码如下:

<
%function cocktailSort_selectionSort(byval b)'鸡尾酒排序,双向选择排序len2=ubound(b)for i=0 to len2\2min=imax=len2-ifor j=i+1 to len2-iif b(min)>
b(j) thenmin=jend ifnextt=b(min)b(min)=b(i)b(i)=tfor j=i to len2-i-1if b(max)<
b(j) thenmax=jend ifnextt=b(max)b(max)=b(len2-i)b(len2-i)=tnextcocktailSort_selectionSort = bend functiona=array(49,38,65,97,76,13,27) response.write "初始顺序: "for i=0 to ubound(a) response.write a(i)&
" "nextresponse.write "<
hr>
" a = cocktailSort_selectionSort(a)response.write "最终排序结果:"for i=0 to ubound(a) response.write a(i)&
" "next %>
(鼠标移到代码上去,在代码的顶部会出现四个图标,第一个是查看源代码,第二个是复制代码,第三个是打印代码,第四个是帮助)


函数cocktailSort_selectionSort(byval b)就是双向选择排序法。




asp鸡尾酒排序法之二“双向选择排序法”