归并排序
来源:互联网 发布:58同城网招聘淘宝客服 编辑:程序博客网 时间:2024/05/22 03:36
package com.sort;public class MergeSort {public static void main(String[] args) {int[] a=new int[]{-6,5,4,3,-2,1};mergeSort(a,0,a.length-1);for(int array:a){System.out.println(array);}}public static void mergeSort(int[]a ,int start, int end){if(start >= end){return;}int mid = (start+end)/2;mergeSort(a, start, mid);mergeSort(a, mid+1, end);merge(a, start, mid, end);}private static void merge(int[] a, int first, int mid, int last) {int[] temp = new int[(last-first+1)]; int i = first;int j = mid + 1; int m = mid;int n = last; int k = 0; 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]; }}
0 0
- 归并排序-归并排序
- 归并和归并排序
- 归并与归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 排序::归并
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- 归并排序
- PHP验证图片制作
- python 内置函数 map、 reduce 、filter
- linux awk命令详解
- 阿里巴巴java研发成功笔面试总结
- OpenVPN优化之-巨型帧
- 归并排序
- poj 3067
- php的页面静态化技术 ob(out_put buffering)
- awk的类sql数据处理
- C语言实现strlen()4种方法和strcat()3种方法
- VI VIM相关命令
- 形象地聊聊C++中的浅拷贝与深拷贝
- JS代码屏蔽鼠标右键点击
- 开源机器人控制平台linuxcnc