Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const f_name1='input.txt';
- f_name2='output.txt';
- var x:array of integer;
- f:text;
- i:integer;
- // Сортировка пузырьком
- Procedure Sort(var x:array of integer; n:integer);
- var i,k,temp:integer;
- flag:boolean;
- Begin
- Flag:=True;
- K:=1;
- While Flag Do
- Begin
- Flag:=False;
- for i:=1 to n-k do if X[i] > X[i+1] then
- Begin
- Temp:=X[i];
- X[i]:=X[i+1];
- X[i+1]:=Temp;
- Flag:=True;
- end;
- Inc(K);
- end;
- end;
- Begin
- if FileExists(F_Name1) then
- Begin
- Assign(F,F_Name1);
- Reset(F);
- While not Eof(F) do
- Begin
- Inc(i);
- SetLength(X,i+1);
- Read(F,X[i]);
- end;
- Close(F);
- Sort(X,X.Length-1);
- Assign(F,F_Name2);
- ReWrite(F);
- for i:=1 to X.Length-1 do Write(F,X[i]+' ');
- Close(F);
- end
- else Writeln('Ошибка: Файл '+F_Name1+' не существует :(');
- end.
Advertisement
Add Comment
Please, Sign In to add comment