电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

数据结构课程设计之java排序

数据结构课程设计之java排序_第1页
1/22
数据结构课程设计之java排序_第2页
2/22
数据结构课程设计之java排序_第3页
3/22
《数据结构课程设计》专业:计算机科学与技术姓名:周兵学号:一、需求分析一、设计代码:1. 直接插入排序:public class InsertSort { public static > void insertSort(T[] array) { for (int i = 1; i <= array.length - 1; i++) { int j = i; while (j>=1 && array[j].compareTo(array[j - 1]) < 0) { T temp = array[j]; array[j] = array[j - 1]; array[j - 1] = temp; j--; } } } public static void main(String[] args) { Integer[] testArray = {23, 25, 12, 42, 35,33,43,57}; System.out.println(" 排序前 :"); for (Integer item : testArray) { System.out.print(item); System.out.print(' '); } System.out.println(); System.out.println("-------------------"); InsertSort.insertSort(testArray); System.out.println(" 排序后 :"); for (Integer item : testArray) { System.out.print(item); System.out.print(' '); } } } 实验结果:2. 折半插入排序:public class BInsertSort { public static void bInsertSort(int[] temp) { int length = temp.length; for (int i = 1; i < length; i++) { int tempVal = temp[i]; int low = 0; int high = i - 1; while (low <= high) { int middle = (low + high) / 2; if (tempVal < temp[middle]) high = middle - 1; else low = middle + 1; } for (int j = i; j > high + 1; j--) temp[j] = temp[j - 1]; temp[high + 1] = tempVal; } } public static void main(String[] args) { int[] a = { 5, 1, 76, 2, 4, 84, 36, 22, 62, 90 }; bInsertSort(a); System.out.println("排序后:"); for (int i = 0; i < a.length; i++) System.out.print(a[i] + " "); }}实验结果:3. 希尔排序:public class InsertionSort {public void shellInertionSort(double [] sorted, int inc){ int sortedLen= sorted.length; for(int j=inc+1;j=0;k-=inc){...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

数据结构课程设计之java排序

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部