2、實(shí)戰(zhàn)練習(xí) 1) 補(bǔ)充代碼(2003秋二(10))
下面是一個(gè)采用拉鋸式排序法對(duì)數(shù)組元素按升序進(jìn)行排序的程序,所謂“拉鋸式排序法”是這一遍把最小的元素從下到上送到最上的位置,下一遍則是從上到下把最大的元素送到最下的位置。
Option Base 1
Private Sub Command1_Click()
Dim a(10) As Integer,i As Integer
For i = 1 To 10
a(i) = Int(Rnd * 10)+1
Text1 = Text1 & Str(a(i))
Next i
Call shaker_sort(a)
For i = 1 To 10
Text2 = Text2 & Str(a(i))
Next i
End Sub
Private Sub Shaker_sort(k() As Integer)
Dim i As Integer,c As Integer,d As Integer
Dim t As Integer
c = 1
d = (1)
Do
For (2) Step-1
If k(i=1)>k(i) Then
t = k(i-1):k(i-1) = k(i):k(i) = t
End If
Next i
(3)
For i = c+1 To d
If (4) Then
t = k(i-1):k(i-1) = k(i):k(i) = t
End If
Next i
d = d-1
Loop While (5)
End Sub
2) 編程題(2002秋上機(jī)試卷04)
把文本框輸入的字符串按降序添加到列表框中。
希望與更多計(jì)算機(jī)等級(jí)考試的網(wǎng)友交流,請(qǐng)進(jìn)入計(jì)算機(jī)等級(jí)考試論壇
更多信息請(qǐng)?jiān)L問(wèn):考試吧計(jì)算機(jī)等級(jí)考試欄目