欢迎来到天天文库
浏览记录
ID:18854774
大小:48.00 KB
页数:26页
时间:2018-09-25
《java中的几种排序方法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、java中的几种排序方法Java中实现排序的那些方法作者:娜来源:程序员之家发布者:admin时间:2009-12-2111:10:30点击:820下面,要和大家分享的是用Java语言实现的各种排序,包括插入排序、冒泡排序、选择排序、Shell排序、快速排序、归并排序、堆排序、SortUtil等。希望对大家有所帮助。插入排序:packageorg.rut.util.algorithm.support;importorg.rut.util.algorithm.SortUtil;publicclassInsertSor
2、timplementsSortUtil.Sort{publicvoidsort(int[]data){inttemp;for(inti=1;i0)&&(data[j]3、SortimplementsSortUtil.Sort{publicvoidsort(int[]data){inttemp;for(inti=0;ii;j--){if(data[j]4、blicclassSelectionSortimplementsSortUtil.Sort{publicvoidsort(int[]data){inttemp;for(inti=0;ii;j--){if(data[j]5、gorithm.support;importorg.rut.util.algorithm.SortUtil;publicclassShellSortimplementsSortUtil.Sort{publicvoidsort(int[]data){for(inti=data.length/2;i>2;i/=2){for(intj=0;j6、rt,intinc){inttemp;for(inti=start+inc;i=inc)&&(data[j]7、il.Sort{publicvoidsort(int[]data){quickSort(data,0,data.length-1);}privatevoidquickSort(int[]data,inti,intj){intpivotIndex=(i+j)/2;//swapSortUtil.swap(data,pivotIndex,j)intk=partition(data,i-1,j,data[j]);SortUtil.swap(data,k,j);if((k-i)>1)quickSort(data,i,k-1)8、;if((j-k)>1)quickSort(data,k+1,j);}privateintpartition(int[]data,intl,intr,intpivot){do{while(data[++l]pivot);SortUtil.swap(data,l,r);}while(l
3、SortimplementsSortUtil.Sort{publicvoidsort(int[]data){inttemp;for(inti=0;ii;j--){if(data[j]4、blicclassSelectionSortimplementsSortUtil.Sort{publicvoidsort(int[]data){inttemp;for(inti=0;ii;j--){if(data[j]5、gorithm.support;importorg.rut.util.algorithm.SortUtil;publicclassShellSortimplementsSortUtil.Sort{publicvoidsort(int[]data){for(inti=data.length/2;i>2;i/=2){for(intj=0;j6、rt,intinc){inttemp;for(inti=start+inc;i=inc)&&(data[j]7、il.Sort{publicvoidsort(int[]data){quickSort(data,0,data.length-1);}privatevoidquickSort(int[]data,inti,intj){intpivotIndex=(i+j)/2;//swapSortUtil.swap(data,pivotIndex,j)intk=partition(data,i-1,j,data[j]);SortUtil.swap(data,k,j);if((k-i)>1)quickSort(data,i,k-1)8、;if((j-k)>1)quickSort(data,k+1,j);}privateintpartition(int[]data,intl,intr,intpivot){do{while(data[++l]pivot);SortUtil.swap(data,l,r);}while(l
4、blicclassSelectionSortimplementsSortUtil.Sort{publicvoidsort(int[]data){inttemp;for(inti=0;ii;j--){if(data[j]5、gorithm.support;importorg.rut.util.algorithm.SortUtil;publicclassShellSortimplementsSortUtil.Sort{publicvoidsort(int[]data){for(inti=data.length/2;i>2;i/=2){for(intj=0;j6、rt,intinc){inttemp;for(inti=start+inc;i=inc)&&(data[j]7、il.Sort{publicvoidsort(int[]data){quickSort(data,0,data.length-1);}privatevoidquickSort(int[]data,inti,intj){intpivotIndex=(i+j)/2;//swapSortUtil.swap(data,pivotIndex,j)intk=partition(data,i-1,j,data[j]);SortUtil.swap(data,k,j);if((k-i)>1)quickSort(data,i,k-1)8、;if((j-k)>1)quickSort(data,k+1,j);}privateintpartition(int[]data,intl,intr,intpivot){do{while(data[++l]pivot);SortUtil.swap(data,l,r);}while(l
5、gorithm.support;importorg.rut.util.algorithm.SortUtil;publicclassShellSortimplementsSortUtil.Sort{publicvoidsort(int[]data){for(inti=data.length/2;i>2;i/=2){for(intj=0;j
6、rt,intinc){inttemp;for(inti=start+inc;i=inc)&&(data[j]7、il.Sort{publicvoidsort(int[]data){quickSort(data,0,data.length-1);}privatevoidquickSort(int[]data,inti,intj){intpivotIndex=(i+j)/2;//swapSortUtil.swap(data,pivotIndex,j)intk=partition(data,i-1,j,data[j]);SortUtil.swap(data,k,j);if((k-i)>1)quickSort(data,i,k-1)8、;if((j-k)>1)quickSort(data,k+1,j);}privateintpartition(int[]data,intl,intr,intpivot){do{while(data[++l]pivot);SortUtil.swap(data,l,r);}while(l
7、il.Sort{publicvoidsort(int[]data){quickSort(data,0,data.length-1);}privatevoidquickSort(int[]data,inti,intj){intpivotIndex=(i+j)/2;//swapSortUtil.swap(data,pivotIndex,j)intk=partition(data,i-1,j,data[j]);SortUtil.swap(data,k,j);if((k-i)>1)quickSort(data,i,k-1)
8、;if((j-k)>1)quickSort(data,k+1,j);}privateintpartition(int[]data,intl,intr,intpivot){do{while(data[++l]pivot);SortUtil.swap(data,l,r);}while(l
此文档下载收益归作者所有