|  | 
|  | 
| вернуться в форум | Pls help with quick sort Послано Emil  30 мар 2008 23:13Can 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 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 мар 2008 13:51procedure 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;
 | 
 | 
|