首页 > 试题广场 >

自然数数组的排序

[编程题]自然数数组的排序
  • 热度指数:2432 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
给定一个长度为N的整形数组arr,其中有N个互不相等的自然数1-N。请实现arr的排序,但是不要把下标位置上的数通过直接赋值的方式替换成
[要求]
时间复杂度为,空间复杂度为 

备注:


输入描述:
第一行有一个整数N。表示数组长度
接下来一行有N个互不相等的自然数1-N。


输出描述:
输出N个整数表示排序后的结果
示例1

输入

5
2 1 4 5 3

输出

1 2 3 4 5 

备注:
头像 wangdx
发表于 2021-03-19 15:00:22
#include <iostream> #include <vector> using namespace std; void swap(vector<int> &arr, int p1, int p2) { int tmp = arr[p1]; 展开全文
头像 瓜瓜请多指教
发表于 2020-07-21 15:11:00
include <bits/stdc++.h> using namespace std; int getIndex(vector<int>& arr,int left,int right){ int tmp=arr[left]; while(left< 展开全文