TRI PAR SELECTION

ricardomaniche Messages postés 29 Date d'inscription   Statut Membre Dernière intervention   -  
ricardomaniche Messages postés 29 Date d'inscription   Statut Membre Dernière intervention   -
public static int[] triSelection(int[] tableau){
int j=0 ;
int min=0;
for (int i = 0; i< tableau.length; i++){
for (int k = j; i< tableau.length; k++){
if(tableau[k]<tableau[min]) min=i;
}
int elem =tableau[i];
tableau[i]=tableau[min];
tableau[min] = elem;
j++;
}
return tableau;
}

J'ai un soucis avec mon algorithme de tri par sélection. Si quelqu'un pourrait m'aider, je le remercie d'avance.

1 réponse

ricardomaniche Messages postés 29 Date d'inscription   Statut Membre Dernière intervention   1
 
public static int[] triSelection(int[] tableau){
int j=0 ;
int min=0;
for (int i = 0; i< tableau.length-1; i++){
for (int k = j; k< tableau.length; k++){
if(tableau[k]<tableau[min]) min=k;
}
j++;
int elem =tableau[i];
tableau[i]=tableau[min];
tableau[min] = elem;
min = j;

}
return tableau;
}
j'ai réussi a le faire fonctionner mais il n'y a pas moyen de le simplfier ?
0