uses crt;
type f=file of integer;
var a,b:f;i,q,w,k,p,j,n,m:integer;
procedure sozd(var ab:f;k1:integer);
begin
k:=10;
rewrite(ab);
for i:=1 to k do begin
q:=random(150)+k1;
write(ab,q);
end;
close(ab);
end;
procedure vivod(var ab:f;t:string;c:byte);
begin
reset(ab);
writeln;
writeln;
writeln(t);
while not eof(ab) do begin
read(ab,q);
write(q,' ');
end;
close(ab);
end;
procedure sort(var ab:f; stype: boolean);
begin
reset(ab);
i:=0;
repeat
seek(ab,i);read(ab,q,w);
if ((q>w) and (stype)) then begin
seek(ab,i);
write(ab,w,q);
if i>0 then dec(i);
end else if ((q<w) and (not stype)) then begin
seek(ab,i);
write(ab,w,q);
if i>0 then dec(i);
end else inc(i);
until i>=filesize(ab)-1;
close(ab);
end;
BEGIN clrscr;
randomize;
assign(a,'a.txt');
assign(b,'b.txt');
sozd(a,0);
vivod(a,'Файл A',12);
sort(a,true);
vivod(a,'Сортировка по возрастанию файла A',10);
reset(a);
sozd(b,100);
vivod(b,'Файл B',12);
sort(b,false);
vivod(b,'Сортировка по убыванию файла B',10);
reset(b);
readkey;
end.
Незнаю как сделать слияние двух файлов в файле С таким образом, чтобы файл С был упорядочен по возрастанию. Слияние производить в соответствии с упорядоченностью файлов А и В (т.е. саму сортировку файла С не делать).
Pascal
Пиши решу Дёшево
ICQ: 410691984
ICQ: 410691984