当前位置: 高中信息技术 / 综合题
  • 1. (2021高二下·浙江期中) 编写一个VB程序,实现程序功能如下:打开程序时,随机产生10个两位正整数存入数组a中,并在列表框List1中显示。单击“排序”按钮Command1后,在列表框List2中显示左右交替上升序列,程序运行界面如下图所示。排序方法:使用选择排序算法将数组改造成左右交替上升序列,即将最小值放在最左端,第2小值放在最右端;再将第3小值放到左端,第4小值放到右端。以此类推,直到形成左右交替上升序列。例如将数组a = (4,8,2,9,3,6,1,7,5,10),排序成a = (1,3,5,7,9,10,8,6,4,2)。

    1. (1) 该程序界面中有几类对象:(填数字)
    2. (2) 实现上述功能的VB程序如下,请在划线处填上合适的代码。

      Const n = 10

      Dim a(1 To n) As Integer

      Private Sub Form_Load()

          For i = 1 To n

              a(i) =        ‘产生两位随机正整数

              List1.AddItem Str(a(i))

          Next i

      End Sub

      Private Sub Command1_Click()

          Dim p As Integer, q As Integer, pos1 As Integer, pos2 As Integer, t As Integer

          p = 1: q = n

          Do While

              If a(p) <= a(p + 1) Then

                  pos1 = p: pos2 = p + 1

              Else

                  pos1 = p + 1: pos2 = p

              End If

              

              For i = p To q

                  If a(i) < a(pos1) Then

                      pos2 = pos1

                      pos1 = i

                  ElseIf a(i) < a(pos2) Then

                      pos2 = i

                  End If

              Next i

              If pos1 <> p Then t = a(pos1): a(pos1) = a(p): a(p) = t

              If pos2 = p Then

              If pos2 <> q Then t = a(pos2): a(pos2) = a(q): a(q) = t

              p = p + 1: q = q - 1

          Loop

          For i = 1 To n

              List2.AddItem Str(a(i))

          Next i

      End Sub

    3. (3) 加框处代码有误,请改正。

微信扫码预览、分享更方便