排序算法
来源:互联网 发布:冰川网络手游怎么样 编辑:程序博客网 时间:2024/04/29 21:48
//直接插入排序
int currentValue;int count=0;for (int i = 1; i < array.length; i++) {currentValue=array[i];int position=i;for (int j = i-1; j >=0; j--) {count++;if(currentValue<array[j]){array[j+1]=array[j];position--;}else {break;}array[position]=currentValue;}}System.out.println(count);
//快速排序
public void SortList(int[] array) {// TODO Auto-generated method stubsubSort(array,0,array.length-1);System.out.println(count);}private void subSort(int[] array, int low, int high) {if(array==null||low>=high){return;}int part=partion(array,low,high);if(part==low){subSort(array,low+1,high);}else if (part==high) {subSort(array, low, high-1);}else {subSort(array, low, part-1);subSort(array, part+1, high);}}private int partion(int[] array, int low, int high) {int position=low;while(low<high){count++;if(position<high){if (array[low]<=array[high]) {high--;}else {int temp=array[high];array[high]=array[low];array[low]=temp;position=high;low++;}}else {if (array[low]<=array[high]) {low++;}else {int temp=array[high];array[high]=array[low];array[low]=temp;position=low;high--;}}}return position;}
//冒泡排序
public void SortList(int[] array) {int count=0;if(array==null||array.length<1){return;}for (int i = 1; i < array.length; i++) {for (int j = 0; j < array.length-i; j++) {count++;if (array[j]>array[j+1]) {int temp=array[j];array[j]=array[j+1];array[j+1]=temp;}}}System.out.println(count);}
1 0
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 排序算法
- 吸一口老霾,体味生活的无味陈杂
- 让程序显示输入错误的提示框
- Java性能 优缺点 和 编码技巧 ——不一定始终对,VM的设计是关键。
- git的小问题CRLF和LF自动转换的warning
- java注解
- 排序算法
- 技术要能够变现才有价值
- codeforces 721D Maxim and Array(贪心)
- 将一台XP添加到WindowsServer2008的域中时不能联系域的域控制器的原因
- yii框架的简单curd
- Java锁的种类以及辨析
- Android入门教程 HttpURLConnection的用法 HTTP请求
- 多路查找树(B树)
- 详解wait和waitpid函数