
8.6 Searching and Sorting Arrays 515
Figure 8.22
Using Selection Sort
Before Selection Sort, the array is
3394 279 1181 2471 3660 221
After Selection Sort, the array is
221 279 1181 2471 3394 3660
is a static method, we call it using the Sorter class name. The output of a
sample run is shown in Figure 8.22.
1 /** Client for Selection Sort
2 * Anderson, Franceschi
3 */
4 import java.util.Random;
5
6 public class SelectionSortClient
7 {
8 public static void main( String []args )
9 {
10 // instantiate an array and fill with random values
11 int []numbers = new int [6];
12 Random rand = new Random();
13 for ( int i = 0; i < numbers.length; i++ )
14 {
15 numbers[i]