P1177 【模板】快速排序
作者:互联网
// Problem: P1177 【模板】快速排序
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1177
// Memory Limit: 125 MB
// Time Limit: 3000 ms
// User: Pannnn
#include <bits/stdc++.h>
using namespace std;
void quickSort(vector<int> &info, int l, int r) {
if (l >= r) {
return;
}
int i = l - 1, j = r + 1;
int x = info[l + r >> 1];
while (i < j) {
do ++i; while (info[i] < x);
do --j; while (info[j] > x);
if (i < j) swap(info[i], info[j]);
}
quickSort(info, l, j);
quickSort(info, j + 1, r);
}
int main() {
int n;
cin >> n;
vector<int> info(n);
for (int i = 0; i < n; ++i) {
cin >> info[i];
}
quickSort(info, 0, n - 1);
for (int i = 0; i < n; ++i) {
cout << info[i] << " ";
}
cout << endl;
return 0;
}
标签:info,int,quickSort,++,P1177,while,排序,模板 来源: https://www.cnblogs.com/pannnn/p/15852951.html