当前位置:网站首页>Acwing785. quick sort (sort+ quick sort + merge sort)
Acwing785. quick sort (sort+ quick sort + merge sort)
2022-06-13 09:25:00 【Age worry】
785. Quick sort
subject
Ideas : It was used sort(a,a+n)、 Quick line up 、 Three methods of merging and sorting
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N];
void sort1(){
sort(a,a+n);
}
void sort2(int l,int r){
if(l>=r) return;
int mid=(l+r)>>1;
//cout<<mid<<endl;
sort2(l,mid);
sort2(mid+1,r);
int t[N],k=0;
int i=l,j=mid+1;
for(;i<=mid && j<=r;){
if(a[i]<=a[j]) t[k++]=a[i++];
else t[k++]=a[j++];
}
while(i<=mid) t[k++]=a[i++];
while(j<=r) t[k++]=a[j++];
for(int i=0;i<k;i++){
a[l+i]=t[i];
}
}
void sort3(int l,int r){
if(l>=r) return ;
int i=l-1,j=r+1,x=a[(l+r)>>1];
while(i<j){
do i++;while(a[i]<x);
do j--;while(a[j]>x);
if(i<j) swap(a[i],a[j]);
}
sort3(l,j);sort3(j+1,r);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
//sort1();
//sort2(0,n-1);
sort3(0,n-1);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}
边栏推荐
- C language: shortcut keys commonly used in VS
- Online debugging tool Arthas advanced
- Attack and defense world PWN shell
- LeetCode 202. 快乐数
- HAProxy + Keepalived实现MySQL的高可用负载均衡
- Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
- 20211108 is transpose multiply a a a positive definite matrix? What are the necessary and sufficient conditions for a to be a positive definite matrix?
- 20211018 some special matrices
- C language: preprocessing in program environment
- Collection of articles on virtualization and cloud computing
猜你喜欢
Use typescript to complete simple snake eating function
(dfs) acwing 842. Arrange numbers
Longadder of the source code of JUC atomic accumulator
Redis fuzzy query batch deletion
C language: deep understanding of pointers and arrays
(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem
IP address introduction
Tutorial (5.0) 04 Fortint cloud services and scripts * fortiedr * Fortinet network security expert NSE 5
Exploitation of competitive loopholes in attacking and defending world PWN play conditions
Jenkins接入Openldap用戶認證
随机推荐
Library management system based on wechat applet Rar (thesis + source code)
删除软链接
LeetCode 322. 零钱兑换
C language: recursive function to realize Hanoi Tower
批量讀取文件夾下的全部語音文件
LeetCode 6096. Success logarithm of spells and potions (binary search)
SQL ROW_ The number() function uses
Heap
Zigzag transformation
Use typescript to complete simple snake eating function
Jenkins接入Openldap用戶認證
Collection of articles on virtualization and cloud computing
攻防世界PWN play 条件竞争漏洞的利用
Figure introduction to database neo4j
LeetCode 6098. Count the number of subarrays whose score is less than K (prefix and + binary search)
LeetCode 5270. 网格中的最小路径代价(动态规划)
C language: Simulated Implementation of library function strcpy
LeetCode 343. 整数拆分
时间戳转localDate
LeetCode 201. Digit range bitwise AND