vb代码中,如何在一组排好序的数组中插入一个数,并按着原来的顺序排列 写出代码,谢谢了 5
3个回答
展开全部
function NumInsert(num,numindex,source_array(),source_array_count) as integer()
rem //num =要插入的数据
rem //numindex =要插入的位置
rem //source_array(),原始队列
rem //source_array_count=原始队列数据数量
dim abc(source_array_count+1) as integer '新建队列
dim i as integer
'将后面的数据复制到新队列
for i= source_array_count to numindex step -1
abc(i+1)=source_array(i)
next
‘ 将前面的数据复制到新队列
for i= 0 to numindex -1
abc(i)=source_array(i)
next
'插入数据
abc(numindex )= num
return abc
end function
rem //num =要插入的数据
rem //numindex =要插入的位置
rem //source_array(),原始队列
rem //source_array_count=原始队列数据数量
dim abc(source_array_count+1) as integer '新建队列
dim i as integer
'将后面的数据复制到新队列
for i= source_array_count to numindex step -1
abc(i+1)=source_array(i)
next
‘ 将前面的数据复制到新队列
for i= 0 to numindex -1
abc(i)=source_array(i)
next
'插入数据
abc(numindex )= num
return abc
end function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim s1() As Integer, I As Integer, s2 As String
Dim t1 As Integer, t2 As Integer
ReDim s1(10)
For I = 0 To 10
s1(I) = I
Next
s2 = InputBox("请输入数值和位置,格式:值|位置", "", "31|2")
If s2 <> "" Then
t1 = Mid(s2, 1, InStr(1, s2, "|") - 1)
t2 = Mid(s2, InStr(1, s2, "|") + 1, 10)
If t2 <= UBound(s1) Then
ReDim Preserve s1(UBound(s1) + 1)
For I = UBound(s1) To t2 Step -1
s1(I) = s1(I - 1)
Next
s1(t2) = t1
Else
ReDim Preserve s1(UBound(s1) + 1)
s1(UBound(s1)) = t1
End If
End If
For I = 0 To UBound(s1)
Print s1(I)
Next
End Sub
Dim s1() As Integer, I As Integer, s2 As String
Dim t1 As Integer, t2 As Integer
ReDim s1(10)
For I = 0 To 10
s1(I) = I
Next
s2 = InputBox("请输入数值和位置,格式:值|位置", "", "31|2")
If s2 <> "" Then
t1 = Mid(s2, 1, InStr(1, s2, "|") - 1)
t2 = Mid(s2, InStr(1, s2, "|") + 1, 10)
If t2 <= UBound(s1) Then
ReDim Preserve s1(UBound(s1) + 1)
For I = UBound(s1) To t2 Step -1
s1(I) = s1(I - 1)
Next
s1(t2) = t1
Else
ReDim Preserve s1(UBound(s1) + 1)
s1(UBound(s1)) = t1
End If
End If
For I = 0 To UBound(s1)
Print s1(I)
Next
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
redim,再在数组里排序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询