例如我要把a1:array[1..100] of integer ;a2:array[1..100] of integer ;
合并到sum:array[1..200] of integer ;的数组!
代码如下:
j:=1;
B:=TRUE;
repeat
//第一个数组归并到sum中间
for i:=low(a1) to high(a1) do
begin
sum[j]:=a1[i];
form1.Label2.Caption := inttostr(sum[j]);
j:=j+1;
end;
//第2个数组归并到sum中间
for i:=low(a2) to high(a2) do
begin
sum[j]:=a1[i];
form1.Label2.Caption := inttostr(sum[j]);
j:=j+1;
end;
if (j=high(sum)) then B:=FALSE;
until B=FALSE;但是运行就出错了!!!
//第一个数组归并到sum中间
for i:=low(a1) to high(a1) do
begin
sum[j]:=a1[i];
form1.Label2.Caption := inttostr(sum[j]);
j:=j+1;
end;
//第2个数组归并到sum中间
for i:=low(a2) to high(a2) do
begin
sum[j]:=a1[i];
form1.Label2.Caption := inttostr(sum[j]);
j:=j+1;
end;
showmessage('完毕!')
干吗要用repeat循环?干吗要做if (j=high(sum)) then B:=FALSE;
的判断?
你在这句话前面打印一下j的值,要我猜的不错这时j=201,而high(sum)=200结果B:=false不会被执行,然后再次回到前面试图写sum[201]时报错.
CopyMemory(@sum[101], @a2[1], 100*sizeof(integer));