当前位置:网站首页>Merge sort divide and conquer
Merge sort divide and conquer
2022-06-11 19:33:00 【*c.】
Divide and conquer algorithm :
1. decompose
2. government
3. Merge
#include<bits/stdc++.h>
using namespace std;
const int N=1e7+10;
void merge(int a[],int low,int high);
void mergesort(int a[],int low,int high);
int main()
{
int a[100000];
int i,n;cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
}
mergesort(a,0,n-1);
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
return 0;
}
void merge(int a[],int low,int mid,int high)// government
{
int *b=new int[high-low+1];//b Is an auxiliary array Using offsite sorting
int i=low,j=mid+1,k=0;
while(i<=mid&&j<=high)
{
if(a[i]<=a[j])
{
b[k++]=a[i++];
}else{
b[k++]=a[j++];
}
}
while(i<=mid)b[k++]=a[i++];
while(j<=high)b[k++]=a[j++];
for(i=low,k=0;i<=high;i++)
{
a[i]=b[k++];
}
delete[] b;// Release
}
void mergesort(int a[],int low,int high)
{
if(low<high)
{
int mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);// decompose
merge(a,low,mid,high);// Merge backtracking
}
}
边栏推荐
- Bottomsheetdialog usage details, setting fillet, fixed height, default full screen, etc
- Database design graduation information management
- 干货丨MapReduce的工作流程是怎样的?
- 556. 下一个更大元素 III-(31. 下一个排列)-两次遍历
- Postman configuration Chinese
- On Workflow selection
- Replace the backbone of target detection (take the fast RCNN as an example)
- Loop filtering to uncover the technical principle behind video thousand fold compression
- 谷歌提出超强预训练模型CoCa,在ImageNet上微调Top-1准确率达91%!在多个下游任务上SOTA!...
- RTL仲裁器设计
猜你喜欢

Key contents that wwdc22 developers need to pay attention to

程序员10年巨变,一切都变了又好像没变...

CMU 15-445 database course lesson 5 text version - buffer pool

Highcharts sets the histogram width, gradient, fillet, and data above the column
![[untitled]](/img/02/49d333ba80bc6a3e699047c0c07632.png)
[untitled]

Automated test requirements analysis

Golang学习笔记—基础篇

Raki's notes on reading paper: memory replace with data compression for continuous learning

CMU 15-445 数据库课程第五课文字版 - 缓冲池

The Economist: WTO MC12 restarts the digital economy and becomes the core engine of global economic recovery and growth
随机推荐
干货!基于序列超图神经网络的信息扩散预测
使用canvas给页面添加文字水印
Kubernetes binary installation (v1.20.15) (VIII) deploying network plug-ins
[Lao Wang's fallacy of brain science] Why do blind people "seem" to be more "sensitive" than normal people?
30讲 线性代数第二讲 矩阵
"Case sharing" based on am57x+ artix-7 FPGA development board - detailed explanation of Pru Development Manual
懂机器学习如何入门量化交易?
Record the phpstudy configuration php8.0 and php8.1 extension redis
High performance architecture design
[image denoising] image denoising based on Markov random field with matlab code
Golang学习笔记—基础篇
[help] how can wechat official account articles be opened in an external browser to display the selected messages below?
【C语言刷题——Leetcode10道简单题】
PyMySQL利用游标操作数据库方法封装!!!
图像变换 torchvision.transforms 笔记
RTL仲裁器设计
Cf:f. shifting string [string rearrangement in specified order + grouping into rings (cutting connected components) + minimum same moving cycle of each group + minimum common multiple]
About my experience of "binary deployment kubernetes cluster"
09-MySQL锁
How are functional components different from class components