q sort(报错模板)

ykj71 2022-10-22 14:48:10 2022-10-22 14:49:39 0
#include<bits/stdc++.h>

using namespace std;

const int N=1e5+10;

int n,a[N];

void quick(int l,int r){

	if(l>=r)return ;

	int mid=l+r>>1,i=l-1,j=r+1;

	while(i<=j){

		do i++;while (a[i]<a[mid]);

		do j--;while (a[j]>a[mid]);

		if(i<j) swap(a[i],a[j]);

	}

	quick(l,j);

	quick(j+1,r);

}

int main(){

scanf("%d",&n);

for(int i=1;i<=n;i++)scanf("%d",&a[i]);

quick(1,n);

for(int i=1;i<=n;i++)printf("%d ",a[i]);

	return 0;

}
{{ vote && vote.total.up }}

共 1 条回复

CPP 刷题王

快排?