public static void selectionSort int array Date startTime new Date int

 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
public static void selectionSort(int[] array) {
Date startTime = new Date();
int sravCount = 0;
int prisCount = 0;
for (int i = 0; i < array.length; i++) {
int min = array[i];
int index = 0;
prisCount++;
sravCount++;
for (int j = i; j < array.length; j++) {
sravCount++;
prisCount++;
if (min > array[j]) { min = array[j]; index = j; sravCount++; prisCount++; }
}
if(array[i] > min) {
int nado = array[i];
array[i] = min;
array[index] = nado;
sravCount++;
prisCount+=3;
}
}
Date endTime = new Date();
System.out.println("Время работы: " + (endTime.getTime() - startTime.getTime()));
System.out.println("Количество сравниваний: " + sravCount);
System.out.println("Количество присвоений: " + prisCount);
}