Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Qucksort;
- {$R+}
- {$O-}
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- var n,i:longint;
- a: packed array[1..100000] of integer;
- procedure Qsort(l,r:longint);
- var i,j,x,y:longint;
- begin
- i:=l;
- j:=r;
- x:=a[l+random(r-l)];
- repeat
- while a[i]<x do
- inc(i);
- while a[j]>x do
- dec(j);
- if i<=j then
- begin
- y:=a[i];
- a[i]:=a[j];
- a[j]:=y;
- inc(i);
- dec(j);
- end;
- until (i>j) ;
- if l<j then
- Qsort(l,j);
- if i<r then
- Qsort(i,r);
- end;
- begin
- reset(input,'input.txt');
- rewrite(output,'output.txt');
- read(n);
- for i := 1 to n do
- read(a[i]);
- Qsort(1,n);
- for i := 1 to n do
- write(a[i],' ');
- end.
Add Comment
Please, Sign In to add comment