vb编程序,在有序数组中插入一个数,在有序数组中删除一个数.
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