网页编程 - ASP重新排序

<%

str="张建民,任家宁,姜春胜,姜 朋,纪伟亮,倪 浩,张显臻,"

adata= split(str,",")

call responsearray(adata,"原来顺序")

call responsearray(selectsort(adata),"选择排序")

call responsearray(quicksort(adata),"快速排序")

call responsearray(insertsort(adata),"插入排序")

call responsearray(bubblesort(adata),"冒泡排序")

'选择排序

function selectsort(a_data)

dim i,j,k

dim bound,t

bound=ubound(a_data)

for i=0 to bound-1

k=i

for j=i+1 to bound

if a_data(k)>a_data(j)then

k=j

end if

next

t=a_data(i)

a_data(i)=a_data(k)

a_data(k)=t

next

selectsort=a_data

end function

'快速排序

function quicksort(a_data)

dim i,j

dim bound,t

bound=ubound(a_data)

for i=0 to bound-1

for j=i+1 to bound

if a_data(i)>a_data(j)then

t=a_data(i)

a_data(i)=a_data(j)

a_data(j)=t

end if

next

next

quicksort=a_data

end function

'冒泡排序

function bubblesort(a_data)

dim bound

bound=ubound(a_data)

dim bsorted,i,t

bsorted=false

do while bound>0 and bsorted=false

bsorted=true

for i=0 to bound-1

if a_data(i)>a_data(i+1)then

t=a_data(i)

a_data(i)=a_data(i+1)

a_data(i+1)=t

bsorted=false

end if

next

bound=bound-1

loop

bubblesort=a_data

end function

'插入排序

function insertsort(a_data)

dim bound

bound=ubound(a_data)

dim i,j,t

for i=1 to bound

t=a_data(i)

j=i

do while t0

a_data(j)=a_data(j-1)

j=j-1

loop

a_data(j)=t

next

insertsort=a_data

end function

'输出数组

sub responsearray(a_data,str)

dim s

s=""

response.write""&str&":"

for i=0 to ubound(a_data)

s=s&a_data(i)&","

next

s=left(s,len(s)-1)

response.write s

response.write"


"

end sub

%>