归并排序
来源:互联网 发布:centos关机命令 编辑:程序博客网 时间:2024/06/05 17:39
#include <iostream>using namespace std;void Merge(int a[],int b[], int start, int mid, int end){int i=start,j=mid+1,k=start;while(i<=mid&&j<=end){if(a[i]>=a[j]){b[k]=a[j];k++;j++;}else{b[k]=a[i];i++;k++;}}while(i<=mid){b[k]=a[i];k++;i++;}while(j<=end){b[k]=a[j];j++;k++;}for(i=start;i<=end;i++) a[i]=b[i];}//内部使用递归void MergeSort(int a[],int b[], int start, int end){ if(start<end) { int mid=(start+end)/2; MergeSort(a,b,start,mid); MergeSort(a,b,mid+1,end); Merge(a,b,start,mid,end); }}int main(){ int a[8] = {50, 10, 20, 30, 70, 40, 80, 60}; int i, b[8]; for(i=0; i<8; i++) cout<<a[i]<<" "; cout<<endl; MergeSort(a, b, 0, 7); for(i=0; i<8; i++) cout<<a[i]<<" "; cout<<endl; return 0;}
0 0
- 归并排序-归并排序
- 归并和归并排序
- 归并与归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 排序::归并
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- Java读取文件方法大全
- dpkg:处理软件包 xxx (--configure)时出错
- 一天一条Linux指令-hostname
- 查看Oracle中是否有锁表的sql
- 搭建HBase单机环境
- 归并排序
- Java 堆 OutOfMemoryError
- c语言的常见问题(一)
- 第一章 第一个c#程序
- bootstrap validator校验用户名已存在的方法
- 微信号码检测工具为什么不能免费使用?(2017)
- Spring整合Hibernate的步骤
- 了解ViewPager
- js校验input框空格输入