当前位置:网站首页>Merge sort ()
Merge sort ()
2022-06-11 02:08:00 【Study hard 867】
#include <bits/stdc++.h>
using namespace std;
int a[1000];
void merge(int left,int mid,int right){
int result=right-left+1;
int b[result];
int n=0;
int temp=left;// Be sure to save the original results
int end=right;// Save original right
int now=mid;
while(left<now&&mid<=end){
if(a[left]<=a[mid]){
b[n++]=a[left];
left++;
}
else {
b[n++]=a[mid];
mid++;
}
}
while(left<now){
b[n++]=a[left];
left++;
}
while(mid<=end){
b[n++]=a[mid];
mid++;
}
n=0;
int i;
for(i=temp;i<=end;i++){
a[i]=b[n++];
}
return ;
}
void mergesort(int left,int right){
if(left==right)return ;
int mid;
mid=(left+right)/2;
mergesort(left,mid);
mergesort(mid+1,right);
merge(left,mid+1,right);
}
int main(){
int n;
scanf("%d",&n);
int i;
memset(a,0,sizeof(a));
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
mergesort(0,n-1);
for(i=0;i<n;i++){
printf("%d ",a[i]);
}
system("pause");
return 0;
}边栏推荐
- 【MATLAB】图像复原
- Our understanding of the industrial Internet may be more out of the existing logic
- [Qt] Erreur: qapplication: No such file or directory Solution
- 20N10-ASEMI中小功率MOS管20N10
- Wrong question (character array)
- Dialog alertdialog, simpledialog, showmodalbottomsheet, showtoast shutter custom dialog
- Understand the role of before and after Clearfixafter clear floating
- [matlab] image compression coding (DCT, RLE)
- Sparrowrecsys recurrence record
- 爱思唯尔---Elseviewer---预印本在线发表通知
猜你喜欢
![[winning] Title A of the 9th Teddy Cup Challenge](/img/86/8445c4ac47d4fa7630544984fa0c58.jpg)
[winning] Title A of the 9th Teddy Cup Challenge

Win11怎么更改管理员头像?Win11更换管理员头像的方法

flutter_ Swiper carousel map plug-in

Task03: building an offline material system

Internet of things final assignment - sleep quality detection system (refined version)

ME11/ME12采购信息记录及条件记录创建及更新BAPI:ME_INFORECORD_MAINTAIN_MULTI

【交通标志识别】基于matlab GUI YCbCr特征提取+BP神经网络交通标志识别【含Matlab源码 1869期】

Asemi FET 12n65 parameters, 12n65 specifications, 12n65 features

ASEMI场效应管12N65参数,12N65规格书,12N65特征

How to change the administrator's Avatar in win11? Win11 method of changing administrator image
随机推荐
Task06: bit operation
Xpath Injection
Alibaba cloud Tianchi online programming training camp_ Task arrangement
Complete tutorial on obtaining voltage from QGC ground station (APM voltage cannot be obtained from QGC)
Task04: String
2021-07-18 ROS notes - basics and communication
[Haas hands on] creative case of new video program launch we started the first phase together E01: Internet of things engineers started the remote control manipulator with you
14:00面试,14:08就出来了 ,问的实在是太...
Understand the role of before and after Clearfixafter clear floating
爱思唯尔---Elseviewer---预印本在线发表通知
QT widget's simple serial port assistant (qserialport)
Byte Beijing 23K and pinduoduo Shanghai 28K, how should I choose?
【MATLAB】图像压缩编码(DCT、RLE)
5月B站榜单丨飞瓜数据UP主成长排行榜(B站平台)发布
Polynomial multiplication
2021-7-18 ROS notes XML language related
Initialize the one-dimensional array a correctly
Coordonnées des capitales provinciales des provinces chinoises
浅析直播间海量聊天消息的架构设计难点
[traffic sign recognition] Based on Matlab GUI YCbCr feature extraction +bp neural network traffic sign recognition [including Matlab source code 1869]