Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. var
  2. mas: array [1..1000] of integer;
  3. k, i: integer;
  4.  
  5. procedure SortMas(L,R:integer);
  6. var X,y,i,j:integer;
  7. begin
  8. X:=mas[(L+R) div 2];
  9. i:=L;
  10. j:=R;
  11. while i<=j do
  12. begin
  13. while mas[i]<X do
  14. i:=i+1;
  15. while mas[j]>X do
  16. j:=j-1;
  17. if i<=j then
  18. begin
  19. y:=mas[i];
  20. mas[i]:=mas[j];
  21. mas[j]:=y;
  22. i:=i+1;
  23. j:=j-1;
  24. end;
  25. end;
  26.  
  27. if L<j then
  28. SortMas(L,j);
  29. if i<R then
  30. SortMas(i,R);
  31. end;
  32.  
  33.  
  34. begin
  35. AssignFile(input, 'input.txt');
  36. reset(input);
  37. read(input, k);
  38. AssignFile(output, 'output.txt');
  39. rewrite(output);
  40. for i:=1 to k do
  41. begin
  42. read(input, mas[i]);
  43. end;
  44. SortMas(1, k);
  45. for i:=1 to k do
  46. begin
  47. write(output, mas[i], ' ');
  48. end;
  49. CloseFile(input);
  50. CloseFile(output);
  51. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement