-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTriSelection3A.java
31 lines (29 loc) · 1.02 KB
/
TriSelection3A.java
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
public class TEST1234 {
public static void main(String[] args) {
int [] tab = {10, 8, 5, 3, 7, 20, 45, 2, 11, 16};
int comparaison=0;
int affectation=0;
int echange=0;
int n = tab.length;
for(int i = 0; i<n-1; i++) {
comparaison++;
int min = i;
affectation+=1;
for(int j=i+1; j<=n-1; j++) {
comparaison++;
if(tab[j] < tab[min]) {
min = j;
affectation+=1;
}
}
int y = tab[i];
tab[i]= tab[min];
tab[min] = y;
echange+=2;
}
for(int i=0; i<n; i++) {
System.out.println(tab[i]);
}
System.out.println("Il y a eu " + comparaison + " comparaisons, " + affectation +" affectations et "+ echange + " echanges.");
}
}