Code:
procedure merge;
begin
reset(f1); reset(f2); rewrite(f);
read(f1,x);
read(f2,x1);
while (not eof(f1)) and (not eof(f2)) do
begin
if (x > x1) then
begin
write(f,x);
read(f1,x);
end
else
begin
write(f,x1);
read(f2,x1);
end;
end;
if (not eof(f1)) then
begin
if (x > x1) then
begin
write(f,x);
write(f,x1);
end
else
begin
write(f,x1);
write(f,x);
end;
while(not eof(f1)) do
begin
read(f1,x);
write(f,x);
end;
end;
if (not eof(f2)) then
begin
if (x > x1) then
begin
write(f,x);
write(f,x1);
end
else
begin
write(f,x1);
write(f,x);
end;
while(not eof(f1)) do
begin
read(f2,x);
write(f,x);
end;
end;
end;
procedure merge;
begin
reset(f1); reset(f2); rewrite(f);
read(f1,x);
read(f2,x1);
while (not eof(f1)) and (not eof(f2)) do
begin
if (x > x1) then
begin
write(f,x);
read(f1,x);
end
else
begin
write(f,x1);
read(f2,x1);
end;
end;
if (not eof(f1)) then
begin
if (x > x1) then
begin
write(f,x);
write(f,x1);
end
else
begin
write(f,x1);
write(f,x);
end;
while(not eof(f1)) do
begin
read(f1,x);
write(f,x);
end;
end;
if (not eof(f2)) then
begin
if (x > x1) then
begin
write(f,x);
write(f,x1);
end
else
begin
write(f,x1);
write(f,x);
end;
while(not eof(f1)) do
begin
read(f2,x);
write(f,x);
end;
end;
end;
f, f1 i f2 su datoteke tipa integer, a x i x1 su integeri. f je izlazna datoteka di ide sortirani niz iz f1 i f2.