@[zhuyunyu](/space/show?uid=77997) 我只会Pascal,但是您的代码中交换后还要写一个i++,j--。
```
procedure qsort(l,r:longint);
var
i,j,mid,t:longint;
begin
i:=l; j:=r; mid:=b[(i+j) div 2];
repeat
while b[i]<mid do inc(i);
while b[j]>mid do dec(j);
if i<=j then
begin
t:=a[i]; a[i]:=a[j]; a[j]:=t;
t:=b[i]; b[i]:=b[j]; b[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
```
by XeCtera @ 2018-05-12 22:11:14
你都会用bits/stdc++.h这个头文件了,为什么不用sort呢?~~(手动滑稽)~~
by lizongru @ 2018-05-12 22:41:19
sort的正确使用方法:
sort(a,a+n);
(a为数组名,n为数组长度/个数)
by Jameswood @ 2018-05-12 22:55:39
@[lizongru](/space/show?uid=20865)
因为我只知道sort排一个数组序,但我想要同时交换ai。所以只能手动打sort。
by zhuyunyu @ 2018-05-13 10:44:05
@[zhuyunyu](/space/show?uid=77997) 用结构体,自己手写cmp函数
by lizongru @ 2018-05-13 16:20:19
- 定义:
```
struct node{
int a,b;
}A[1000001];
inline bool cmp(node a,node b){
return a.b<b.b;
}
```
- 使用:
```
sort(A+1,A+1+n,cmp);
```
手打的,不知道有没有哪里写错。
by lizongru @ 2018-05-13 16:23:34
luogu把我的缩进吃了。。。
by lizongru @ 2018-05-13 16:24:09