题目

小李基于选择排序算法编写了一个VB程序,功能如下:在文本框Text1中显示排序前的数据,单击“排序”按钮Command1,在文本框Text2中显示剔除重复数据后的升序排序结果。程序运行界面如下图所示。算法的思路:第i趟排序从a(i)….a(bottom)中查找最小值并记录其下标k,同时将后面的每个元素与a(i)比较是否重复,若发现重复数据,进行剔除处理;找到最小值与a(i)交换。 实现上述功能的VB程序如下,在划线处填入合适的代码。 Const n = 10 Dim a(1 To n) As Integer Private Sub Command1_Click()   Dim i As Integer, j As Integer, t As Integer   Dim k As Integer, bottom As Integer   '获取排序前数据,依次存储在数组 a 中,并在文本框 Text1 中显示。代码略   bottom = n: i = 1   Do While i <= bottom - 1     k = i: j = bottom     Do While j > i       If a(j) < a(k) Then         k = j       ElseIf a(j) = a(i) Then '若发现重复数据,进行剔除处理         a(j) = a(bottom)       IfThen k = j         bottom = bottom - 1       End If       j = j - 1     Loop     If k <> i Then       t = a(k): a(k) = a(i): a(i) = t     Else           End If   Loop   For i = 1 To     Text2.Text = Text2.Text + Str(a(i))   Next i End Sub 答案:【1】k=bottom【2】i=i+1【3】bottom
信息技术 试题推荐
最近更新