归并排序
来源:互联网 发布:网站的优化 编辑:程序博客网 时间:2024/05/22 16:07
//归并排序 #include<bits/stdc++.h> using namespace std;int a[10]={13,27,19,2,8,12,8,30,89};int b[10];void Merge(int a[],int s,int m,int e,int tmp[]){int pb=0;int p1=s,p2=m+1;//指针p1,p2 while(p1<= m &&p2<= e){if( a[p1] <a[p2]) tmp[pb++]=a[p1++];else tmp[pb++]=a[p2++];}while(p1<=m) tmp[pb++]=a[p1++];while(p2<=e) tmp[pb++]=a[p2++];for(int i=0;i<e-s+1;++i) a[s+i]=tmp[i];}void MergeSort(int a[],int s,int e,int tmp[]){if(s<e){int m=s+ (e-s)/2;MergeSort(a,s,m,tmp);MergeSort(a,m+1,e,tmp);Merge(a,s,m,e,tmp);}}int main(){int size =sizeof(a)/sizeof(int);MergeSort(a,0,size-1,b);for(int i=0;i<size;++i) cout<<a[i]<<",";cout<<endl;return 0;}
阅读全文
0 0
- 归并排序-归并排序
- 归并和归并排序
- 归并与归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 排序::归并
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 机器学习 正则化
- 33-把数组排成最小的数
- x264直接编码
- freemarker加载模板文件的三种方法
- Webservice 之eclipse 创建axis1.4项目
- 归并排序
- opencv学习(一)
- Spring 整合之 Ehcache
- Pyhton运算符与表达式
- Aspose.slides记录(三)
- Java 性能优化系列之3.1[JVM调优]
- RateLimiter限流
- [美团 CodeM 复赛]城市网络
- nginx 在windows中的安装和配置