Java Reference
In-Depth Information
7 public class SelectionSortDemo
8 {
9 public static void main(String[] args)
10 {
11 int [] a =
ArrayUtil.randomIntArray( 20 , 100 );
12 System.out.println(Arrays.toString(a));
13
14 SelectionSorter sorter = new
SelectionSorter(a);
15 sorter.sort();
16
17 System.out.println(Arrays.toString(a));
18 }
19 }
630
631
ch14/selsort/ArrayUtil.java
1 import java.util.Random;
2
3 /**
4 This class contains utility methods for array manipulation.
5 */
6 public class ArrayUtil
7 {
8 /**
9 Creates an array filled with random values.
10 @param length the length of the array
11 @param n the number of possible random values
12 @return an array filled with length numbers between
13 0 and n - 1
14 */
15 public static int [] randomIntArray( int
length, int n)
16 {
17 int [] a = new int [length];
18 for ( int i = 0 ; i < a.length; i++)
19 a[i] = generator.nextInt(n);
20
21 return a;
22 }
Search WWH ::




Custom Search