数据结构与算法题目集7-12——排序

版权声明:我的GitHub:https://github.com/617076674。真诚求星! https://blog.csdn.net/qq_41231926/article/details/84679700

我的数据结构与算法题目集代码仓:https://github.com/617076674/Data-structure-and-algorithm-topic-set

原题链接:https://pintia.cn/problem-sets/15/problems/720

题目描述:

知识点:排序

思路:用sort函数排序

时间复杂度是O(NlogN)。空间复杂度是O(N)。

C++代码:

#include<iostream>
#include<algorithm>

using namespace std;

long long nums[100000];

int main(){
	int N;
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%lld", &nums[i]);
	}
	sort(nums, nums + N);
	for(int i = 0; i < N; i++){
		printf("%lld", nums[i]);
		if(i != N - 1){
			printf(" ");
		}else{
			printf("\n");
		}
	}
	return 0;
} 

C++解题报告:

猜你喜欢

转载自blog.csdn.net/qq_41231926/article/details/84679700