在一个数组中插入数据?怎么插?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在一个数组中插入数据?怎么插?相关的知识,希望对你有一定的参考价值。
将一个正数插到从小到大排列的正数序列中Var
A:array[1..10000] of word;
i,n:integer;
Procedure insert(var n:integer;x:word);
Var I,j:integer;
Begin
If x>a[n] then a[n+1]:=x
Else if x<=a[1] then begin
For I:=n downto 1 do a[i+1]:=a[i];
A[1]:=x;
End
Else begin
For I:=1 to n-1 do if (x>a[i])and(x<=a[i+1] ) then begin j:=I; break; end;
For I:=n downto j+1 do a[i+1]:=a[i];
A[j+1]:=x;
End;
Inc(n);
End;
begin
n:=1;
a[1]:=3;
insert(n,4);
insert(n,1);
insert(n,2);
for i:=58 downto 1 do insert(n,i);
for i:=1 to n do write(a[i]:3);
end. 参考技术A Private Sub CreateData(n() As Integer)
Dim i As Integer
Dim j As Integer
Dim temp As Integer
Print "ÔʼÊý¾ÝΪ£º"
Randomize
For i = 1 To 20
n(i) = Int(Rnd * 90) + 10
Print n(i);
If i Mod 10 = 0 Then Print
Next i
Print "´ÓСµ½´óÅÅÐò£º"
For i = 1 To 19
For j = i + 1 To 20
If n(i) > n(j) Then temp = n(i): n(i) = n(j): n(j) = temp
Next j
Print n(i);
If i Mod 10 = 0 Then Print
Next i
Print n(i)
End Sub
Private Sub Form_Click()
Dim m(1 To 21) As Integer
Dim position As Integer
Dim i As Integer
Dim nflag As Integer
Dim x As Integer
CreateData m()
x = Val(InputBox("ÇëÊäÈëÒª²åÈëµÄÕûÊý"))
Print "Òª²åÈëµÄÕûÊýΪ£º"; x
position = 1
For i = 1 To 20
If m(i) > x Then
position = i
nflag = 1
Exit For
End If
Next i
If nflag = 1 Then
For i = 20 To position Step -1
m(i + 1) = m(i)
Next i
m(position) = x
Else
m(21) = x
End If
Print "²åÈëxºóµÄÊý×éΪ:"
For i = 1 To 21
Print m(i);
If i Mod 10 = 0 Then Print
Next i
End Sub本回答被提问者和网友采纳 参考技术B js中使用push() ;你知道你想知道什么语言的
以上是关于在一个数组中插入数据?怎么插?的主要内容,如果未能解决你的问题,请参考以下文章