-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
42 lines (33 loc) · 799 Bytes
/
Copy pathSelectionSort.java
File metadata and controls
42 lines (33 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Random;
public class SelectionSort
{
public static void selection_sort( int[] a )
{
// Your code goes here
}
public static void swap( int[] a , int i, int j )
{
// Your code goes here
}
public static void main( String[] args )
{
Random r = new Random();
int[] arr = new int[10];
int i;
// Fill up the array with random numbers
for ( i=0; i<arr.length; i++ )
arr[i] = 1 + r.nextInt(100);
// Display it
System.out.print("before: ");
for ( i=0; i<arr.length; i++ )
System.out.print( arr[i] + " " );
System.out.println();
// Sort it
selection_sort( arr );
// Display it again to confirm that it's sorted
System.out.print("after : ");
for ( i=0; i<arr.length; i++ )
System.out.print( arr[i] + " " );
System.out.println();
}
}