ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1613. For Fans of Statistics

Show all messages Hide all messages

Pls help with quick sort Emil 30 Mar 2008 23:13
Can any body wright me code of quick sort?
It's a very important thing,but i don't know it.
Re: Pls help with quick sort KIRILL(ArcSTUpid coder:) 31 Mar 2008 00:17
sort array mas of integer between l and r

Procedure Qsort(l,r:integer);
var x,i,j,y:integer;
begin
 i:=l; j:=r;  x:=mas[(l+r) shr 1];
repeat
  while mas[i]<x do inc(i);
  while mas[j]>x do dec(j);
  if i<=j then
     begin
        y:=mas[i]; mas[i]:=mas[j];  mas[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;
Re: Pls help with quick sort Ferman 31 Mar 2008 13:51
procedure sort(r,l:longint);
 var
  i,j,x,b:longint;
 begin
  i:=r;
  j:=l;
  x:=ar[(i+j) div 2];
  repeat
   while ar[i]>x do inc(i);
   while ar[j]<x do dec(j);
   if i<=j then
    begin
     b:=ar[i];
     ar[i]:=ar[j];
     ar[j]:=b;
     inc(i);
     dec(j);
    end;
  until i>j;
  if j>r then sort(r,j);
  if l>i then sort(i,l);
 end;