一道vf题.,,..求帮忙 用多重循环做随机产生10个数,用冒泡,选择,插入三种...
发布网友
发布时间:2023-12-23 13:34
我来回答
共2个回答
热心网友
时间:2024-07-30 15:30
只写算法了,写全程序太多了
冒泡排序
a[1]~a[10]:10个随机数
for i = 1 to 10 do
for j= i to 10 do
if a[j]>a[i] then
x= a[j]
a[j]=a[i]
a[i]=x
end
选择排序
a[1]~a[10]:10个随机数
b[1]~b[10]:空数列
for i= 10 downto 1 do
{x=1
for j= 1 to i do
[
if a[j]>a[x] then x=j
]
b[i]=a[x]
}
插入排序
用指针很方便,数组麻烦。
a[1]~a[10]:10个随机数
b:空链表
b=a[1]
for i =2 to 10 do
{
while (b<a[i])or (b=null) do
[b=b.next]
b=a[i]
b =b.first
}
热心网友
时间:2024-07-30 15:26
冒泡排序:
clear
dimension a(10)
?"排序前:"
for i=1 to 10
a(i)=int(rand()*100)
??a(i)
endfor
for i=1 to 10
for j=1 to 10-i
if a(j+1)<a(j)
t=a(j)
a(j)=a(j+1)
a(j+1)=t
endif
endfor
endfor
?"排序后:"
for i=1 to 10
??a(i)
endfor
选择排序:
clear
dimension a(10)
?"排序前:"
for i=1 to 10
a(i)=int(rand()*100)
??a(i)
endfor
for i=1 to 9
k=i
for j=i+1 to 10
if a(j)<a(k)
k=j
endif
endfor
if k!=i
t=a(i)
a(i)=a(k)
a(k)=t
endif
endfor
?"排序后:"
for i=1 to 10
??a(i)
endfor
插入排序:
clear
dimension a(11)
?"排序前:"
for i=2 to 11
num=int(rand()*100)
??num
a(1)=num
for j=i-1 to 1 step -1
if num<a(j)
a(j+1)=a(j)
else
a(j+1)=num
exit
endif
endfor
endfor
?"排序后:"
for i=2 to 11
??a(i)
endfor