快排双关键字

 1 var
 2 i,j,l,m,n:longint;
 3 a,b:array[0..10000]of longint;
 4 procedure px(l,r:longint);
 5  var
 6  i,j,k,m,x,y:longint;
 7  begin
 8   i:=l;
 9   j:=r;
10   x:=a[(i+j) div 2];
11   y:=b[(i+j) div 2];
12  repeat
13   while (a[i]<x)or((a[i]=x)and(b[i]<y)) do inc(i);
14   while (a[j]>x)or((a[j]=x)and(b[j]>y)) do dec(j);
15   if i<=j then
16   begin
17      k:=a[i];a[i]:=a[j];a[j]:=k;
18      k:=b[i];b[i]:=b[j];b[j]:=k;
19     inc(i);
20     dec(j);
21    end;
22   until i>j;
23   if i<r then px(i,r);
24   if j>l then px(l,j);
25 end;
26  begin
27  readln(n);
28  for i:=1 to n do
29   begin
30    read(a[i]);
31    read(b[i]);
32   end;
33  px(1,n);
34  for i:=1 to n do
35   writeln(a[i],' ',b[i]);
36 end.

 

相关文章:

  • 2021-12-09
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-12-09
  • 2021-11-19
猜你喜欢
  • 2021-07-28
  • 2021-12-31
  • 2022-01-30
  • 2021-07-09
  • 2021-07-08
  • 2021-10-30
  • 2022-12-23
相关资源
相似解决方案