选择排序和冒泡排序

来源:百度知道 编辑:UC知道 时间:2024/06/05 16:03:10
4,5,9,3,2,给这样五个数分别用冒泡排序和选择排序法做一遍,谢谢

dim i,j ,t as integer
dim a(4) as integer
for i=0 to 4
a(i)=inputbox("请输入你要排序的第"+(i+1).tostring+"个数")
next i
for i=0 to 4
for j=0 to 4-i
if a(j)>a(j+1)
t=a(j+1)
a(j+1)=a(j)
a(j)=t
end if 冒泡升序
next
next

选择升序
dim i,j ,t,k as integer
dim a(4) as integer
for i=0 to 4
a(i)=inputbox("请输入你要排序的第"+(i+1).tostring+"个数")
next i
for i=0 to 4
for j=0 to 4
if a(i)<a(j)
t=a(i)
for k=0 to j-2
a(k)=a(k+1)
next
a(k+1)=t
end if
next
next