郓城县中医院各科室:关于VB操作,跪求!

来源:百度文库 编辑:高校问答 时间:2024/05/05 17:01:41
冒泡排序!
麻烦各位哥哥姐姐帮我编下!用冒泡排序

产生10个20到50之间的两位随机整数,用二分法查找其中是否有36这个数,若有请输出其在数组中的位置,没有请给出相应的提示信息

冒泡排序:
dim i,j,temp, a(10)
for i=0 to ubound(a)
a(1)=int(rnd * 10)+1
next i

for i=0 to ubound(a)
for j=i+1 to ubound(a)
if a(i)> a(j) then
temp=a(j)
a(J)=a(i)
a(i)=temp)
end if
next j
next i

for i=0 to uboud(a)
print a(i)
next i
'二分
dim l,h,m b(50)
'产生随机数
for i=0 to ubound(b)
b(i)=(rnd*50)+20
next i
'排序
for i=0 to ubound(b)
for j=i+1 to ubound(b)
if b(i)> b(j) then
temp=b(j)
b(J)=b(i)
b(i)=temp)
end if
next j
next i
'二分查找
l=0
h=ubound(b)
do while (l<=h)
m=(l+h)/2
if b(m)=36 then
print m
exit do
end if
if b(m)>36 then
h=m
else
l=m+1
end if
loop

才10分 一般没人做吧...