Skip to content

Commit 5e9d458

Browse files
committed
🧹 - Spring cleaning
1 parent f8c0d16 commit 5e9d458

9 files changed

Lines changed: 53 additions & 3 deletions

File tree

Tri-a-bulle-normal/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

Tri-a-bulle-normal/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>tri-a-bulle-normal</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
File renamed without changes.

Tri-a-bulle-normal/Algorithm-Recursif.algo

Whitespace-only changes.

Tri-a-bulles-optimise/src/Iteratif.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.util.Random;
44

55
public class Iteratif {
6+
7+
public static float comparaisons;
8+
public static float echanges;
9+
public static float affectations;
610

711
public static void main(String[] args) {
812
// write your code here
@@ -12,18 +16,25 @@ public static void main(String[] args) {
1216
Random rand = new Random();
1317

1418
// Tableau de test
15-
int[] tableau = { rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100) };
16-
17-
System.out.println(Arrays.toString(triBulle(tableau)));
19+
// int[] tableau = { rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100) };
20+
int[] tableau = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
21+
// System.out.println(Arrays.toString(triBulle(tableau)));
22+
23+
stat(10, 20, 5, 10);
24+
25+
// System.out.println("Résultat de " + comparaisons + " comparaisons, " + echanges + " échanges et " + (echanges * 3) + " affectations");
1826
}
1927

2028
public static int[] triBulle(int [] tableau) {
2129
int n = tableau.length;
30+
2231
boolean echange = true;
2332
while (echange) {
2433
echange = false;
2534
for (int i = 0; i < n - 1; i++) {
35+
comparaisons++;
2636
if (tableau[i] > tableau[i + 1]) {
37+
echanges++;
2738
int temp = tableau[i];
2839
tableau[i] = tableau[i + 1];
2940
tableau[i + 1] = temp;
@@ -34,4 +45,25 @@ public static int[] triBulle(int [] tableau) {
3445

3546
return tableau;
3647
}
48+
49+
public static void stat(int min,int max, int step, int nbr) {
50+
int i;
51+
for ( i = 1 ; i <= nbr ; i++) {
52+
int Tab[] =new Random().ints(min).toArray();
53+
triBulle(Tab);
54+
}
55+
if (min < max && i>nbr) {
56+
stat((min+step),max,step,nbr);
57+
} else {
58+
System.out.println("Le nombre de comparaisons est de " + comparaisons/nbr);
59+
System.out.println("Le nombre d'échanges est de " + echanges/nbr);
60+
61+
if (min < max && i>nbr) {
62+
System.out.println("Le nombre d'affectations pour " + min + " est de " + (echanges * 3)/nbr);
63+
stat((min+step),max,step,nbr);
64+
} else {
65+
System.out.println("Le nombre d'affectations pour " + min + " est de " + (echanges * 3)/nbr);
66+
}
67+
}
68+
}
3769
}

Tri-de-selection/Algorithm-Recursif.algo

Whitespace-only changes.

Tri-insertion/Algorithm-Recursif.algo

Whitespace-only changes.

0 commit comments

Comments
 (0)