跳到正文

题解

P1177 题解

Zhu_tian_yu约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年5月23日
收录
2026年10月17日
更新
2026年11月10日
篇幅
约 1 分钟
题目
P1177

版本

  1. v1当前

题意

将一组数排序后输出。

思路

排序算法有很多种,如快速排序、插入排序等。本文介绍用 sort 函数进行排序。

sort 实现原理

具体参照这篇文章。

sort 利用快排思想,底层利用插入排序确保稳定性。

复杂度分析

sort 的时间复杂度为 O(n log n),空间复杂度为 O(n)。

用法

C++
sort(首元素地址,尾元素地址的下一个地址【,比较函数】)

比较函数缺省默认递增排序。

代码

C++
#include<bits/stdc++.h>
using namespace std;
int n,a[114514];
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)cout<<a[i]<<' ';
}
原文