@[Matisse_to_art](/user/1278584)
$O(n^2)$ 太慢了,换$O(n*\log n)$ 的排序算法
by Smile_Cindy @ 2024-02-23 10:14:09
@[Smile_Cindy](/user/87058) 我会呀```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5;
ll a[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
sort(a,a+n);
for(int j=0;j<n;j++) printf("%lld ",a[j]);
return 0;
}
```
我就想问这个冒泡排序怎么改
by VirtualImage @ 2024-02-23 10:19:26
@[Matisse_to_art](/user/1278584) `sort` 是干嘛的,冒泡不T谁T
by HeYilin @ 2024-02-23 10:19:36
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5;
ll a[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
sort(a,a+n);
for(int j=0;j<n;j++) printf("%lld ",a[j]);
return 0;
}
```
by VirtualImage @ 2024-02-23 10:20:01
@[Matisse_to_art](/user/1278584)
不可能改得过啊…
by Smile_Cindy @ 2024-02-23 10:24:39
楼主可以另辟蹊径
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5;
ll a[maxn];
void swap(int& a,int& b){
int t=a;a=b;b=t;
}
void bsort(int n){
for(int i=0;i<n;i++){
for(int j=0;j<n-i;j++){
if(a[j]<a[j-1]) swap(a[j],a[j-1]);
}
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
sort(a,a+n);
for(int j=0;j<n;j++) printf("%d ",a[j]);
return 0;
}
```
by ccf666 @ 2024-02-23 10:27:10
@[ccf666](/user/545404) 想笑。
by 秦屎皇 @ 2024-02-23 10:34:08
@[ccf666](/user/545404) 6
by scy_love_zb @ 2024-02-23 10:34:31
@[ccf666](/user/545404) 6
by VirtualImage @ 2024-02-23 10:39:44
不知道希尔能不能过,等会我写一个试试 @[Matisse_to_art](/user/1278584)
by xzy_caiji @ 2024-02-23 10:43:31