作业帮 > 综合 > 作业

编写子过程Sub Array(a() As Integer,Ir As Boolean,n As Integer)

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/13 08:32:35
编写子过程Sub Array(a() As Integer,Ir As Boolean,n As Integer)
该过程的功能是该过程的功能是使数组元素左移或者右移若干位.其中参数a()是数组,Ir指示位移方向(Ture向左移,false向右移),n确定移动的位数
利用VB语言编写,
编写子过程Sub Array(a() As Integer,Ir As Boolean,n As Integer)
直接用关键字Array与VB冲突,所以加个1
过程名用Array1
Private Sub Array1(a() As Integer,Ir As Boolean,n As Integer)
Dim dd() As Integer
Dim L As Integer
Dim U As Integer
Dim i As Integer
Dim K As Integer
L = LBound(a)
U = UBound(a)
ReDim dd(L To U)
If Ir Then '左移
For i = L To U
K = i + n
If K > U - L + 1 Then
K = K Mod (U - L + 1)
End If
dd(i) = a(K)
Next i
Else '右移
For i = L To U
K = i - n
If K