这种排序方式难道不比快速排序好吗?
  • 板块学术版
  • 楼主joe_zxq
  • 当前回复28
  • 已保存回复28
  • 发布时间2023/8/25 14:58
  • 上次更新2023/11/3 01:18:16
查看原帖
这种排序方式难道不比快速排序好吗?
623577
joe_zxq楼主2023/8/25 14:58

这种排序方式难道不比快速排序好吗?

时间复杂度 O(NlogN)O(N logN) 而且非常稳定!

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int n;
multiset<int>s;
int q[N];
int main() {
	scanf("%d",&n);
	for(int i = 0; i < n ; i++) scanf("%d",&q[i]);
	for(int i = 0; i < n ; i++)s.insert(q[i]);
	for(multiset<int>::iterator it=s.begin();it!=s.end();it++)printf("%d ",*it);
	return 0;
}
2023/8/25 14:58
加载中...