数组元素的插入 VB

程序要求:数组a中存放着升序排列的10个元素,现将一个新数据x插入到数组a中,使插入后的数组仍有序,且数组中各元素的值用随机函数产生,在窗体上分别输入插入前后的数组各元素... 程序要求:数组a中存放着升序排列的10个元素,现将一个新数据x插入到数组a中,使插入后的数组仍有序,且数组中各元素的值用随机函数产生,在窗体上分别输入插入前后的数组各元素值。
谢谢~~各位,这个问题紧急,大家帮帮忙吧~!
展开
 我来答
楼三龙骊颖
2019-04-29 · TA获得超过3921个赞
知道大有可为答主
回答量:3212
采纳率:32%
帮助的人:228万
展开全部
Private
Sub
Form_Click()
Form1.Cls
Dim
A(10)
As
Integer,
B(11)
As
Integer
Dim
I
As
Integer,
J
As
Integer,
X
As
Integer,
T
As
Boolean
Randomize
For
I
=
1
To
10
A(I)
=
Int(Rnd
*
100)
Next
Print
"随机产生的数组是:";
For
I
=
1
To
9
For
J
=
I
+
1
To
10
If
A(I)
>
A(J)
Then
A(0)
=
A(I)
A(I)
=
A(J)
A(J)
=
A(0)
End
If
Next
Print
A(I);
Next
Print
A(10)
X
=
Int(Val(InputBox("插入值
X
",
"输入",
Int(Rnd
*
100))))
Print
"插入";
X;
"后数组为:";
J
=
1
T
=
False
For
I
=
1
To
10
If
X
>
A(I)
Then
B(J)
=
A(I)
Else
If
T
Then
B(J)
=
A(I)
Else
B(J)
=
X
Print
"(";
B(J);
")";
J
=
J
+
1
B(J)
=
A(I)
T
=
True
End
If
End
If
Print
B(J);
J
=
J
+
1
Next
If
Not
T
Then
B(J)
=
X
Print
B(J);
End
If
Print
End
Sub
Private
Sub
Form_Load()
Form1.AutoRedraw
=
True
Print
"程序要求:数组a中存放着升序排列的10个元素,"
Print
"现将一个新数据x插入到数组a中,使插入后的数组仍有序,"
Print
"且数组中各元素的值用随机函数产生,"
Print
"在窗体上分别输入插入前后的数组各元素值。
"
Print
Print
"单击窗口开始......"
End
Sub
已经运行过。
Yuqi_Tan

推荐于2016-09-11 · TA获得超过8.9万个赞
知道大有可为答主
回答量:9918
采纳率:93%
帮助的人:3485万
展开全部
Private Sub Form_Click()
Form1.Cls
Dim A(10) As Integer, B(11) As Integer
Dim I As Integer, J As Integer, X As Integer, T As Boolean
Randomize
For I = 1 To 10
A(I) = Int(Rnd * 100)
Next
Print "随机产生的数组是:";
For I = 1 To 9
For J = I + 1 To 10
If A(I) > A(J) Then
A(0) = A(I)
A(I) = A(J)
A(J) = A(0)
End If
Next
Print A(I);
Next
Print A(10)
X = Int(Val(InputBox("插入值 X ", "输入", Int(Rnd * 100))))
Print "插入"; X; "后数组为:";
J = 1
T = False
For I = 1 To 10
If X > A(I) Then
B(J) = A(I)
Else
If T Then
B(J) = A(I)
Else
B(J) = X
Print "("; B(J); ")";
J = J + 1
B(J) = A(I)
T = True
End If
End If
Print B(J);
J = J + 1
Next
If Not T Then
B(J) = X
Print B(J);
End If
Print
End Sub

Private Sub Form_Load()
Form1.AutoRedraw = True
Print "程序要求:数组a中存放着升序排列的10个元素,"
Print "现将一个新数据x插入到数组a中,使插入后的数组仍有序,"
Print "且数组中各元素的值用随机函数产生,"
Print "在窗体上分别输入插入前后的数组各元素值。 "
Print
Print "单击窗口开始......"
End Sub

已经运行过。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
许舒南灵秋
2019-03-27 · TA获得超过3522个赞
知道小有建树答主
回答量:3053
采纳率:26%
帮助的人:423万
展开全部
Private
Sub
Form_Click()
Form1.Cls
Dim
A(10)
As
Integer,
B(11)
As
Integer
Dim
I
As
Integer,
J
As
Integer,
X
As
Integer,
T
As
Boolean
Randomize
For
I
=
1
To
10
A(I)
=
Int(Rnd
*
100)
Next
Print
"随机产生的数组是:";
For
I
=
1
To
9
For
J
=
I
+
1
To
10
If
A(I)
>
A(J)
Then
A(0)
=
A(I)
A(I)
=
A(J)
A(J)
=
A(0)
End
If
Next
Print
A(I);
Next
Print
A(10)
X
=
Int(Val(InputBox("插入值
X
",
"输入",
Int(Rnd
*
100))))
Print
"插入";
X;
"后数组为:";
J
=
1
T
=
False
For
I
=
1
To
10
If
X
>
A(I)
Then
B(J)
=
A(I)
Else
If
T
Then
B(J)
=
A(I)
Else
B(J)
=
X
Print
"(";
B(J);
")";
J
=
J
+
1
B(J)
=
A(I)
T
=
True
End
If
End
If
Print
B(J);
J
=
J
+
1
Next
If
Not
T
Then
B(J)
=
X
Print
B(J);
End
If
Print
End
Sub
Private
Sub
Form_Load()
Form1.AutoRedraw
=
True
Print
"程序要求:数组a中存放着升序排列的10个元素,"
Print
"现将一个新数据x插入到数组a中,使插入后的数组仍有序,"
Print
"且数组中各元素的值用随机函数产生,"
Print
"在窗体上分别输入插入前后的数组各元素值。
"
Print
Print
"单击窗口开始......"
End
Sub
已经运行过。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
WzyJerry
2009-05-17 · 超过15用户采纳过TA的回答
知道答主
回答量:52
采纳率:0%
帮助的人:39.1万
展开全部
ReDim Preserve a(11)
a(11)=rnd
r=rnd
for i =1 to 10
if r>a(i) then
for k=10 downto i+1 do
a(k+1)=a(k)
a(i+1)=r
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式