当前位置:网站首页>DS sort -- quick sort
DS sort -- quick sort
2022-07-24 14:47:00 【Running star dailu】
Title Description
Give a data sequence , Use the quick sort algorithm to sort from small to large
-- Procedural requirements --
If you use C++ Can only include A header file iostream; If you use C Language can only include A header file stdio
If in the program include More than one header file , Don't look at the code , do 0 Sub processing
It is not allowed to use third-party objects or functions to realize the requirements of this topic
Input
First line input t, Express t Test examples
Second line input n, Indicates that the first example has n Data
In the third line, enter n Data , Positive integers , Space between data
And so on
Output
Each group of test data , Output the result of each fast queue , That is, arrange one number at a time ( The length is 1 The subsequence , No row , No output ). Separate different test data with blank lines .
The sample input
2
6
111 22 6 444 333 55
8
77 555 33 1 444 77 666 2222
Sample output
55 22 6 111 333 444
6 22 55 111 333 444
6 22 55 111 333 444
6 22 55 111 333 444
1 33 77 555 444 77 666 2222
1 33 77 555 444 77 666 2222
1 33 77 77 444 555 666 2222
1 33 77 77 444 555 666 2222
1 33 77 77 444 555 666 2222
Code
#include "iostream"
using namespace std;
const int maxn=1e5+20;
int t,n,a[maxn];
void display(){
for(int i=1;i<=n;i++){
if(i!=1) cout<<" ";
cout<<a[i];
}
cout<<endl;
}
void qisort(int ll,int rr){
if(ll>=rr) return;
int l=ll,r=rr;
int res=a[l];
while(l<r){
while(r>l && a[r]>=res) r--;
if(a[r]<res) a[l]=a[r],l++;
while(l<r && a[l]<=res) l++;
if(a[l]>res) a[r]=a[l],r--;
}
a[l]=res;
display();
qisort(ll,l-1);
qisort(l+1,rr);
}
int main(){
// freopen("123.in","r",stdin);
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
qisort(1,n);
cout<<endl;
}
return 0;
}边栏推荐
- Dialog manager Chapter 2: create frame window
- Property datasource is required exception handling [idea]
- AtCoder Beginner Contest 261E // 按位思考 + dp
- 看完这篇文章,才发现我的测试用例写的就是垃圾
- CSDN垃圾的没有底线!
- 【MATLAB】MATLAB画图系列二 1.元胞与数组转化 2.属性元胞 3.删除nan值 4.合并多fig为同一fig 5.合并多fig至同一axes
- Atcoder beginer contest 261e / / bitwise thinking + DP
- JS judge whether the data is empty
- SQL的SELF JOIN用法
- JS judge whether it is an integer
猜你喜欢

Sword finger offer II 001. integer division

小熊派 课程导读

ISPRS2018/云检测:Cloud/shadow detection based on spectral indices for multi/hyp基于光谱指数的多/高光谱光学遥感成像仪云/影检测

kali简洁转换语言方法(图解)
![Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布](/img/fd/c7bff1ce199e8b600761d77828c674.png)
Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布

茅台冰淇淋“逆势”走红,跨界之意却并不在“卖雪糕”

Detailed explanation of address bus, data bus and control bus

Maotai ice cream "bucked the trend" and became popular, but its cross-border meaning was not "selling ice cream"

REST风格

"After 00" is coming! Digital data ushers in a new generation of "codeless" forces
随机推荐
Regular expression and bypass cases
Su Chunyuan, founder of science and technology · CEO of Guanyuan data: making business use is the key to the Bi industry to push down the wall of penetration
JS judge whether the data is empty
Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
Unity 委托 (Delegate) 的简单理解以及实现
VSCode如何调试Nodejs
onBlur和onChange冲突解决方法
AtCoder Beginner Contest 261 F // 树状数组
[oauth2] II. Authorization method of oauth2
北京一卡通以35288.8529万元挂牌出让68.45%股权,溢价率为84%
[NLP] next stop, embossed AI
Data analysis and mining 2
Differences between C language pointer and array A and &a, &a[0], etc
Learning rate adjustment strategy in deep learning (1)
Ztree tree Metro style mouse through the display user-defined controls add, edit, delete, down, up operations
How to set packet capturing mobile terminal
The sliding window of Li Kou "step by step" (209. The smallest sub array, 904. Fruit baskets)
Kotlin类与继承
Automated penetration scanning tool
Mini examination - examination system