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
|
public class Tri{
public static void main(String[] args){
String[][] tab = {{"at", "0"}, {"ba", "5"}, {"ba", "7"}, {"ba", "3"}, {"cc", "4"}, {"cc", "2"}, {"cc", "1"}, {"dg", "3"}};
int i = 0;
while(i < tab.length - 1){
int cles_consecutives = 0;
for(int j = i; j < tab.length - 1 && tab[j][0] == tab[j+1][0]; j++){
cles_consecutives++;
}
if(cles_consecutives > 0){
for(int j = i; j < i + cles_consecutives; j++){
String element_courant = tab[j + 1][1];
int k = j;
for(; k >= i && Integer.parseInt(tab[k][1]) > Integer.parseInt(element_courant); k--){
tab[k + 1][1] = tab[k][1];
}
if(k < j){
tab[k + 1][1] = element_courant;
}
}
i += cles_consecutives;
}
else{
i++;
}
}
affiche(tab);
}
} |
Partager