📄 driver.java
字号:
/** 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -