Answer the question
In order to leave comments, you need to log in
Why doesn't 'Quick Sort' work?
In general, I write quick sort, I rewrite it as from the Internet, but it does not work.
procedure quicksort(var d:mass; n:integer);
PROCEDURE sort(l,r:integer);
var i,j,k:integer; b:integer;
b1,x:real;
begin
i:=l;
j:=r;
k:=(l+r) div 2;
x:=d[k].res;
repeat
while d[i].res<x do inc(i);
while d[j].res>x do dec(j);
if i<=j
then begin
b1:=d[i].res;
d[i].res:=d[j].res;
d[j].res:=b1;
b:=d[i].ch;
d[i].ch:=d[j].ch;
d[j].ch:=b;
b:=d[i].zn;
d[i].zn:=d[j].zn;
d[j].res:=b;
inc(i);
dec(j);
end;
until i>j;
if i<r
then sort(i,r);
if j>l
then sort(l,j);
end;
begin
sort(1,k);
end.
type rec=record
ch:integer;
zn:integer;
res:real;
end;
type mass=array [1..19819] of rec;
var d:mass;
n,zn,ch,k,i,z,b,c,c1:integer;
f:boolean;
b1:real;
function gcd(x,y:integer):integer;
begin
if y=0
then gcd:=x else gcd:=gcd(y,x mod y);
end;
procedure quicksort(var d:mass; n:integer);
PROCEDURE sort(l,r:integer);
var i,j,k:integer; b:integer;
b1,x:real;
begin
i:=l;
j:=r;
k:=(l+r) div 2;
x:=d[k].res;
repeat
while d[i].res<x do inc(i);
while d[j].res>x do dec(j);
if i<=j
then begin
b1:=d[i].res;
d[i].res:=d[j].res;
d[j].res:=b1;
b:=d[i].ch;
d[i].ch:=d[j].ch;
d[j].ch:=b;
b:=d[i].zn;
d[i].zn:=d[j].zn;
d[j].res:=b;
inc(i);
dec(j);
end;
until i>j;
if i<r
then sort(i,r);
if j>l
then sort(l,j);
end;
begin
readln(n);
k:=0;
for zn:=2 to n do begin
for ch:=1 to zn-1 do
begin
if (zn mod ch<>0) or (ch=1)
then begin
if gcd(ch,zn)=1
then begin inc(k); d[k].ch:=ch; d[k].zn:=zn; d[k].res:=ch/zn; end;
end;
end;
end;
z:=k;
sort(1,k);
for i:=1 to k do
writeln(d[i].ch,'/',d[i].zn);
end.
Answer the question
In order to leave comments, you need to log in
You have to call it differently. Create an array and pass it as an argument to quicksort(..)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question