冒泡法升序排序标准代码(Vb):
for i=1 to 99
for j=i+1 to 100
if a(i)>a(j) then
temp=a(i):a(i)=a(j):a(j)=temp
end if
next j
next i
程序思想是:
冒泡排序法:\x0d\x0a\x0d\x0aOption Explicit\x0d\x0a\x0d\x0aPrivate Sub Form_Click()\x0d\x0aConst N = 10\x0d\x0aDim i%, a(1 To N), m%, j%, t%\x0d\x0aRandomize\x0d\x0a\x0d\x0aFor i = 1 To N '随机输出10个1位数\x0d\x0aa(i) = Int(Rnd * 9 + 1)\x0d\x0aPrint a(i)\x0d\x0aNext i\x0d\x0aPrint\x0d\x0a\x0d\x0aFor i = 1 To N - 1 '采用冒泡排序\x0d\x0a For j = 1 To N - 1\x0d\x0a If a(j) >a(j + 1) Then\x0d\x0at = a(j): a(j) = a(j + 1): a(j + 1) = t\x0d\x0a End If\x0d\x0aNext j\x0d\x0a Next i\x0d\x0a\x0d\x0aFor i = 1 To N '输出排序后的数字\x0d\x0aPrint a(i)\x0d\x0aNext i\x0d\x0aPrint欢迎分享,转载请注明来源:内存溢出
评论列表(0条)