归并排序
来源:互联网 发布:ipad阅读pdf软件 编辑:程序博客网 时间:2024/06/05 15:36
原文链接:http://blog.csdn.net/morewindows/article/details/6678165
void MergeArray(int *a,int first,int mid,int last,int temp){ int i = first,j = mid + a; int m = mid,n = last; while(i <= m && j <= n){ if(a[i] < a[j]) temp[k++] = a[i++]; else temp[k++] = a[j++]; } while(i <= m) temp[k++] = a[i++]; while(j <= n) temp[k++] = a[j++]; for(i = 0;i < k;i++) a[first + i] = temp[i];}void MergeSortStep(int *a,int first,int last,int *temp){ if(first < last){ int mid = (first + last) / 2; MergeSortStep(a,first,mid - 1,temp); MergeSortStep(a,mid + 1,last,temp); MergeArray(a,first,mid,last,temp); }}bool MergeSort(int *a,int n){ int *p = new int[n]; if(p == NULL) return false; MergeSortStep(a,0,n - 1,p); return true;}
0 0
- 归并排序-归并排序
- 归并和归并排序
- 归并与归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 排序::归并
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- sql语句delete----关联两表删除两表内容
- Android 一般动画Animation和属性动画Animator
- Context
- Java中的数据库处理—增删改查
- debug调试
- 归并排序
- 空格替换(剑指offer+程序员面试金典)+string类知识点讲解
- MySQL线程池总结(二)
- MySQL 存储过程的优缺点
- 华为求字符串最后单词长度
- 洛谷2524 Uim的情人节礼物·其之弐解题报告
- 查看Eclipse的版本号
- 为人处事之道
- 点评互联网创业的“南派”和“北派”