题型:单选题 题类:常考题 难易度:普通
【bj】高中信息技术综合库——排序算法及程序实现2
Dim flag(0 To 4) As Boolean, p As Integer
For i=1 To 4
flag(i)=False
Next i
i=1: flag(0)=True
Do While i <= 4 And flag(i-1)
For j=5 To i+1 Step-1
If a(j)<a(j-1) Then
k=a(j):a(j)=a(j-1):a(j-1)=k
flag(i)=True
End If
Next j
i=i+1
Loop
数组元素a(1)到a(5)值依次为“16,4,24,33,77”,程序运行后,flag数组中为True个数及i的值分别是( )
原始数据 | 65 | 57 | 59 | 44 | 45 | 69 |
第1遍 | 44 | 65 | 57 | 59 | 45 | 69 |
第2遍 | 44 | 45 | 55 | 57 | 59 | 69 |
第3遍 | 44 | 45 | 57 | 65 | 59 | 69 |
… | … | … | … | … | … | … |
例如,有如下年龄存在数组a中:
a(1) | a(2) | a(3) | a(4) | a(5) | a(6) | a(7) | a(8) | a(9) | a(10) |
20 | 19 | 18 | 19 | 15 | 12 | 15 | 20 | 17 | 19 |
利用一个数组b(b(10 To 20))记录每个数出现的次数:
b(10) | b(11) | b(12) | b(13) | b(14) | b(15) | b(16) | b(17) | b(18) | b(19) | b(20) |
0 | 0 | 1 | 0 | 0 | 2 | 0 | 1 | 1 | 3 | 2 |
根据数组b对数组a进行排序:
a(1) | a(2) | a(3) | a(4) | a(5) | a(6) | a(7) | a(8) | a(9) | a(10) |
12 | 15 | 15 | 17 | 18 | 19 | 19 | 19 | 20 | 20 |
Dim a(10000) As Integer ‘存放读入的年龄数据
Dim b(100) As Integer ‘存放各个年龄出现的个数
Private Sub Command1_Click()
‘从数据库读入年龄数据放入数组a中
End Sub
Private Sub Command2_Click()
For i = 1 To 100
b(i) = 0
Next i
For i = 1 To 10000 ‘统计每个年龄数据的个数
①
Next i
End Sub
Private Sub Command3_Click()
j = 0
For i = 1 To 100
If b(i) <> 0 Then
Do While b(i) <> 0
②
a(j) = i
‘③
Loop
End If
Next i
For i = 1 To 10000
List2.AddItem Str(a(i))
Next i
End Sub
试题篮