下面程序的功能是从键盘读取A,B数组的元素,A,B数组均已从小到大排好序(无相同元素),现将A,B合并为数组C,同样要求数组C也是从小到大排好序(有相同元素时只保留一个)。
程序中N表示数组A,B的长度,i,j,k分别表示数组A,B,C的取数或存数的指针。
[程序清单]
program excp3;
const n=8; m=2*n;
type arr1=array[1..n]of integer;
arr2=array[1..m]of integer;
var a,b :arr1; c :arr2; i,j,k :integer;
procedure copy(x:arr1;var y:arr2;var i,j:integer);
begin i:=i+1;y[i]:=x[j];j:=j+1; end;
begin
for i:=1 to n do read(a[i]);readln;
for i:=1 to n do read(b[i]);readln;
i:=1;j:=1;________k:=0________
while___________(i<=n)and (j<=n)__________do.
if a[i]<b[j] then copy (a,c,k,i)
else if b[j]<a[i] then copy (b,c,k,j)
else begin
copy(a,c,k,i);
___________j:=j+1__________
end;
while___________i<=n___________do copy(a,c,k,i);
while___________j<=n__________do copy(b,c,k,j);
for i:=1 to k do write (c[i]:4);
writeln;
end.