1樓:沙慧月
使用選擇排序法
假設值都放在陣列裡
假設有a(0)-a(9)
**for i=0 to 8
for j=i+1 to 9
if a(i)>a(j) then
temp=a(i)
a(i)=a(j)
a(j)=temp
next
next
這樣就可把數從小到大進行排列
2樓:匿名使用者
你的**呢?沒有**怎麼「每一步的講解」?
在vb中用快速排序法的例子
3樓:vb妮可
private sub command1_click()dim i%, j%, m%, s(9)
randomize
'下面先生成陣列,裡面是10個隨機數
for i = 0 to 9
s(i) = int(rnd * 101)next
print "原陣列:"; join(s)'下面開始排序
for i = 0 to 9
for j = i + 1 to 9
if s(j) < s(i) then m = s(i): s(i) = s(j): s(j) = m
next
next
print "排序後陣列:"; join(s)end sub
4樓:
ls幾個回答都是氣泡排序(時間複雜度o(n^2)),人家要的可是快速排序(時間複雜度o(n log n))
'text1:輸入框,用空格分隔的數字
'text2:輸出框
'command1:排序命令
private sub command1_click()
dim k() as string, num() as double, s as long, l as long, i as long
k = split(text1.text, " ")
l = ubound(k): s = lbound(k): redim num(l)
for i = s to l
num(i) = val(k(i))
next i
call quick_sort(s, l, num)
for i = s to l
k(i) = num(i)
next i
text2.text = join(k, " ")
end sub
'快速排序程式****************************************===
private sub exchange(byref n1 as double, byref n2 as double)
dim t as double
t = n1: n1 = n2: n2 = t
end sub
private function partition(byval p as long, byval r as long, byref a() as double) as long
dim x as double, t as long, i as long, j as long
randomize
t = clng((r - p) * rnd + p)
call exchange(a(r), a(t))
x = a(r): i = p - 1
for j = p to r - 1
if a(j) <= x then i = i + 1: call exchange(a(i), a(j))
next j
call exchange(a(i + 1), a(r))
partition = i + 1
end function
private sub quick_sort(byval p as long, byval r as long, byref a() as double)
if p < r then
dim q as long
q = partition(p, r, a)
call quick_sort(p, q - 1, a)
call quick_sort(q + 1, r, a)
end if
end sub
快速排序的vb程式,**
5樓:飄葉雜談
dim b
dim i as integer, j as integer, t as integer
private sub command1_click()
b = array(8, 5, 6, 3, 5, 9, 10, 2, 1, 4)
print "排序前:"
for i = 0 to 9
print b(i);
next
end sub
private sub command2_click()
for i = 1 to 9
for j = 1 to 10 - i
if b(j - 1) > b(j) then
t = b(j - 1)
b(j - 1) = b(j)
b(j) = t
end if
next j
next i
print "排序後:"
for i = 0 to 9
print b(i);
next
end sub
private sub command3_click()
dim a(1 to 10), x as integer
dim low as integer, high as integer
dim flag as integer, mid as integer
for i = 1 to 10
a(i) = b(i - 1)
next
print "在"; "a(i)=";
for i = 1 to 10
print a(i);
next
print "中查詢"
high = ubound(a)
low = lbound(a)
x = val(inputbox("輸入要查詢的數"))
flag = 0
do while flag = 0 and high >= low
mid = (high + low) \ 2 '中間的數的下標
if a(mid) = x then
flag = 1
else
if x < a(mid) then
high = mid - 1
else
low = mid + 1
end if
end if
loop
if high < low then
print "沒有要找的數"
else
print "要查的數是a("; mid; ")="; x
end if
end sub
private sub command4_click()
for i = 1 to 10
a(i) = val(inputbox("請輸入a(" & i & ")的值"))
print a(i);
next
end sub
6樓:匿名使用者
我在外地,我手裡暫時沒vb,
很想幫你,建議用電子**也就可以了
希望對你有用
vb**求快速排序的遞迴演算法**?
7樓:匿名使用者
public sub quicksort(byref astrsort() as string, byval lngleft as long, byval lngright as long)
dim i as long
dim j as long
dim temp as string
i = lngleft
j = lngright
temp = astrsort(i)
nextstep: do until i >= j
while (astrsort(j) > temp and j > i)
j = j - 1
end while
if j > i then
astrsort(i) = astrsort(j)
astrsort(j) = temp
i = i + 1
end if
while (astrsort(i) < temp and j > i)
i = i + 1
end while
if j > i then
astrsort(j) = astrsort(i)
astrsort(i) = temp
j = j - 1
end if
loop
if lngleft < i - 1 then quicksort(astrsort, lngleft, i - 1)
if lngright > i + 1 then quicksort(astrsort, i + 1, lngright)
end sub
將陣列的第10到20個元素用快速演算法遞迴排序
quicksort(a, 10, 20)
8樓:匿名使用者
病情分析:
新生兒出生後抵抗力低下,感冒可能和著涼有關,表現為鼻塞、流涕、打噴嚏等症狀,
指導意見:
建議結合當地醫生服用小兒速效感冒顆粒、利巴韋林顆粒,多喂水,根據氣溫適當增減衣服,有發熱時積極藥物退熱,
病情分析:
根據您以上描述初步考慮大概是急性上呼吸道感染指導意見:
可以給予小兒氨酚黃那敏顆粒**,讓寶寶多喝水,家人也要注意預防感冒,若感冒了記得戴上口罩接觸寶寶,祝健康
vb快速排序演算法 不明白原理 求教 懸賞100
9樓:匿名使用者
dim i as long,j as long,aa()as string,t as string
'假設資料存放bai在一個du未知長度的陣列aa裡面
for i=0 to ubound(aa)
for j=0 to ubound(aa)-i
if aa(j)>aa(j+1) then
t=aa(j)
aa(j)=aa(j+1)
aa(j+1)=t
next j
next i
'當i迴圈第
zhi一dao次執行的時候(i=0),
回j迴圈從陣列aa的第一元素迴圈到答
最後一個元素,並將最大值存放在了aa的最後一個元素裡面。
'當i迴圈第二次執行的時候(i=1),只要比較aa陣列從第一個元素到倒數第二個元素就可以了,因為倒數第一個元素已經是最大值的元素了。
'當i迴圈第三次執行的時候(i=2),只要比較aa陣列從第一個元素到倒數第三個元素就可以了,因為倒數第一個元素和倒數第二個元素已經是最大值的元素了。
'依此類推,直到i迴圈aa元素個數次之後,j迴圈就從aa元素的倒數第一個元素排列到了正數第一個元素
這就是著名的氣泡排序法的遞增演算法(從小到大排序)。
反之遞減演算法就是把aa(j)>aa(j+1)換成aa(j) 呵呵,借鑑一下樓上的。加了一個 為了不讓隨機出來的數重複。private sub command1 click dim s 1 to 8,1 to 8 as integerdim stra 1 to 900 as integerdim maxs as integer,l as integer,r a... shutdown主要是xp系統的一個程式,可以用於關閉系統等操作在vb中 shell shutdown l 是shutdown 的一個引數 意思是登出使用者 shell shutdown r t 0 是重啟 等待時間為0秒 shell shutdown s t 0 是關閉系統 private dec... 首先將漢字轉為ascii碼陣列,然後對ascii碼陣列排序。再將ascii碼陣列轉換為字元,大功告成了。以下 經測試完全正確。dim lasc j as long private sub command1 click dim i as long,j as long,k as long dim r a...VB陣列排序題目
vb怎樣編寫快速關機,vb怎樣編寫一個快速關機
VB將文字框中的漢字按拼音排序