vb编程序,在有序数组中插入一个数,在有序数组中删除一个数.

要求先输出有序数组,然后输入插入或删除的数,最后显示插入或删除后的有序数组.... 要求先输出有序数组,然后输入插入或删除的数,最后显示插入或删除后的有序数组. 展开
 我来答
jay821120
推荐于2017-12-16 · TA获得超过262个赞
知道小有建树答主
回答量:269
采纳率:0%
帮助的人:329万
展开全部

Dim a() As Integer, i As Integer, j As Integer, k As Integer

Private Sub Command1_Click()
Dim k As Integer
k = Val(Text1.Text)
For i = 1 To 6
   If k < a(i) Then
      Exit For
   End If
Next i
For j = 6 To i Step -1
   a(j + 1) = a(j)
Next j
a(i) = k
For i = 1 To 7
   Print a(i);
Next i
Print
End Sub

Private Sub Command2_Click()
Dim k1 As Integer
k1 = Val(Text1.Text)
For i = 1 To 7
If k1 = a(i) Then Exit For
Next i
For j = i + 1 To 7
   a(j - 1) = a(j)
Next j
For i = 1 To 6
   Print a(i);
Next i
End Sub

Private Sub Command3_Click()
ReDim a(1 To 7) As Integer
For i = 1 To 6
   a(i) = Int(Rnd * 101)
Next i
For i = 6 To 2 Step -1
   For j = 1 To i - 1
      If a(j) > a(j + 1) Then
         t = a(j)
         a(j) = a(j + 1)
         a(j + 1) = t
      End If
   Next j
Next i
For i = 1 To 6
   Print a(i);
Next i
Print
End Sub

Private Sub Form_Load()
Label1.Caption = "请输入要删除或插入的数"
Text1 = ""
Command1.Caption = "插入"
Command2.Caption = "删除"
Command3.Caption = "生成随机序数"
End Sub

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式