@@ -7,17 +7,17 @@ public class Main {
77 public static void main (String [] args ) {
88 System .out .print ("\033 \033 " );
99
10- int [] tableau = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 };
10+ int [] tableau = { 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 };
1111
12- System .out .println ("Tableau de test : " + Arrays .toString (tri (tableau )));
12+ System .out .println ("Tableau de test : " + Arrays .toString (triInsertion (tableau )));
1313 System .out .println ("Nombre d'échanges : " + echanges );
1414 System .out .println ("Nombre de comparaisons :" + comparaison );
1515 System .out .println ("Nombre d'affectations :" + affectation );
1616 stat (10 ,20 ,5 ,10 );
1717
1818 }
1919
20- public static int [] tri (int [] tableau )
20+ public static int [] triInsertion (int [] tableau )
2121 {
2222 int taille = tableau .length ;
2323
@@ -34,13 +34,12 @@ public static int[] tri(int[] tableau)
3434 while (j >= 0 && tableau [j ] > x )
3535 {
3636 tableau [j +1 ] = tableau [j ];
37+ j --;
3738 echanges ++;
3839 affectation +=1 ;
3940 comparaison +=2 ;
40- j --;
41-
42-
43- }
41+ }
42+
4443 tableau [j +1 ] = x ;
4544
4645 }
@@ -49,10 +48,13 @@ public static int[] tri(int[] tableau)
4948
5049 public static void stat (int min ,int max , int step , int nbr ) {
5150 int i ;
51+ affectation = 0 ;
52+ echanges = 0 ;
53+ comparaison = 0 ;
5254
5355 for ( i = 1 ; i <= nbr ; i ++) {
5456 int tableau [] =new Random ().ints (min ).toArray ();
55- tri (tableau );
57+ triInsertion (tableau );
5658 }
5759 if (min < max && i >nbr ) {
5860 System .out .println ("Le nombre d'affectations pour " + min + " est de " + affectation /nbr );
0 commit comments