当前位置:网站首页>Acwing785. Quick sort
Acwing785. Quick sort
2022-07-19 12:29:00 【Science and technology big pig】
Give you a length of n The whole number sequence of .
Please use quick sort to sort this sequence from small to large .
And output the ordered sequence in order .
Input format
There are two lines of input , The first line contains integers n.
The second line contains n It's an integer ( All integers are in 1∼10^9 Within the scope of ), Represents the whole sequence of numbers .
Output format
The output is one line , contain n It's an integer , It's an ordered sequence .
Data range
1≤n≤100000
sample input :
5
3 1 2 4 5
sample output :
1 2 3 4 5#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int q[N];
void quick_sort(int q[], int l, int r)
{
if (l >= r) return;
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j)
{
do {
i ++;
}while (q[i] < x);
do{
j -- ;
}while (q[j] > x);
if (i < j) swap(q[i], q[j]);
}
quick_sort(q, l, j);
quick_sort(q, j + 1, r);
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i ++ ) scanf("%d", &q[i]);
quick_sort(q, 0, n - 1);
for (int i = 0; i < n; i ++ ) printf("%d ", q[i]);
return 0;
}
边栏推荐
- HCIP(5)
- Notes on the fifth day
- 超声波传感器(CH101&ch201) - Ⅱ
- Committer identity unknown *** Please tell me who you are...
- Opencv tutorial 03: how to track an object in a video
- July training (day 17) - breadth first search
- 云犀聚焦店播解决方案,加速全球化布局
- Opencv based on DLCO descriptor matching
- Configuring OSPF experiment in mGRE environment
- Acwing785. 快速排序
猜你喜欢

The leader of the new generation of cloud database -- AWS

Opencv based on DLCO descriptor matching

Leetcode 150. Evaluation of inverse Polish expression

ros(26):ros::Time::now(),ros::Duration,toSec(),toNSec();计算程序执行时间

Softmax和Cross-entropy是什么关系?

微机原理与技术接口 实验四 子程序及中断实验

MyCat2搭建mysql主从分离

C language drawing example - flower pattern

超声波传感器(CH101&ch201) - Ⅱ

01 knapsack interview questions series (I)
随机推荐
Committer identity unknown *** Please tell me who you are...
Genesis and bluerun ventures have in-depth exchanges
Machine learning Assignment 1
对Rapidly-exploring Random Trees(RRT)路径规划方法的理解
Familiar with nestjs (beginner)
机器学习(上)吴恩达
李宏毅《机器学习》|1. Introduction of this course(机器学习介绍)
HCIP(8)
My favorite 10 machine learning official account
S32K148_CAN驱动(裸机开发)
Acwing786. 第k个数
Microcomputer principle and technical interface experiment five basic IO operation temperature control experiment
10分钟自定义搭建行人分析系统,检测跟踪、行为识别、人体属性All-in-One!
查看mysql数据表结构的两种方法你会吗?
go web
ATT&CK实战系列——红队实战(—)
Core base station_ The error "no gateways configured" is reported when starting the CPA file
RingBuffer
超声波传感器(CH101&ch201) - Ⅱ
熟悉NestJS (新手篇)