-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectSort.java
More file actions
32 lines (28 loc) · 904 Bytes
/
Copy pathSelectSort.java
File metadata and controls
32 lines (28 loc) · 904 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
import java.util.Random;
public class SelectSort {
private static void selectSort(int[] array) {
int current = 0, min = 0;
int t = 0;
for (current = 0; current < array.length - 1; current++) {
min = current;
for (int i = current + 1; i < array.length; i++) {
if (array[i] < array[min]) {
min = i;
}
}
t = array[min];
array[min] = array[current];
array[current] = t;
}
}
public static void main(String[] args) {
int[] array = new int[100000];
Random rand = new Random();
for (int i = 0; i < array.length; i++) {
array[i] = rand.nextInt();
}
long start = System.currentTimeMillis();
selectSort(array);
System.out.println(System.currentTimeMillis() - start);
}
}