driver.java
来自「Java程序设计(美) David D. Riley著 机械工业出版社 书籍配套」· Java 代码 · 共 44 行
JAVA
44 行
/** Selection Sort Program (Figure 12.22) * Author: David Riley * Date: June, 2004 */public class Driver { public Driver() { double[] theArray; theArray = new double[30]; for (int k = 0; k!=theArray.length; k++) { theArray[k] = Math.random(); } selectionSort( theArray ); for (double d : theArray) { System.out.println(d); } } /** post: arr is the same as arr@pre with item values permuted * and for all j [0<=j<arr.length-1) [arr[j] >= arr[j+1]] */ public void selectionSort( double[] arr ) { int selectedIndex; double selectedValue; int lastSorted = -1; while ( lastSorted != arr.length-1 ) { selectedIndex = lastSorted+1; for (int k = lastSorted+2; k<arr.length; k++) { if (arr[k] > arr[selectedIndex]) { selectedIndex = k; } } lastSorted++; // swap arr[selectedIndex] with arr[lastSorted] selectedValue = arr[selectedIndex]; arr[selectedIndex] = arr[lastSorted]; arr[lastSorted] = selectedValue; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?