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 43 44 45 46 47
| public class Tri {
/**
* @param args
*/
public static void triselection(int[]tab)
{
/* if (tab.length == 0) {
throw new IllegalArgumentException("Un tableau vide n'a pas de maximum");
}*/
int i,j,min=0,temp,cpt;
cpt=14;
for(i=0;i<cpt-1;i++)
{
min=i;
for(j=i+1;j<cpt;j++)
{
if(tab[j]<tab[min])
min=j;
}
}
if(min!=i){
temp=tab[min];
tab[min]=tab[i];
tab[i]=temp;
}
for (j=0;j<cpt;j++){
System.out.println(tab[j]+"");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] t={48,17,9,50,35,88,67,43,55,4};
triselection(t);
}
} |
Partager