2018-05-15 · 知道合伙人互联网行家
关注
展开全部
代码如下: Private Sub Form_Click() Dim a(11) As Integer '定义整形变量 Cls Print "排序前:" For i = 1 To 10 Randomize '产生随机数 a(i) = Int(100 * Rnd + 100) '对数组赋值 Print a(i); Next i For i = 1 To 9 '排序处理 p = i For j = p + 1 To 10 If a(p) > a(j) Then p = j Next j t = a(i) a(i) = a(p) a(p) = t Next i Print Print "插入前排序:" For i = 1 To 10 '输出排序结果 Print a(i); Next i Print Print "插入后排序:" n = Val(InputBox("输入一个100~200之间的正整数", "输入")) '输入待插入值 For i = 1 To 10 '插入值排序处理 If n < a(1) Then '插入值小于所有元素 For j = 10 To 1 Step -1 a(j + 1) = a(j) Next j a(1) = n Exit For '排序完毕后退出循环 ElseIf n > a(i) And n <= a(i + 1) Then '插入值范围在数组之间 For j = 10 To i + 1 Step -1 a(j + 1) = a(j) Next j a(i + 1) = n Exit For '排序完毕后退出循环 Else '插入值大于所有元素 a(11) = n End If Next i For i = 1 To 11 '输出插入后排序结果 Print a(i); Next i End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询