Skip to content

Commit f8c0d16

Browse files
authored
Merge pull request #8 from CodingFactory-Repos/feature/tri_a_bulles_normal
🔃 - Merge feature/tri_a_bulles_normal to develop
2 parents 4d23e37 + 3404cf0 commit f8c0d16

4 files changed

Lines changed: 116 additions & 0 deletions

File tree

Tri-a-bulles-optimise/.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@
1414
<natures>
1515
<nature>org.eclipse.jdt.core.javanature</nature>
1616
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1634804850562</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
1728
</projectDescription>

Tri-de-selection/.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,15 @@
1414
<natures>
1515
<nature>org.eclipse.jdt.core.javanature</nature>
1616
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1634804850577</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
1728
</projectDescription>

tri-a-bulle-normal/Algorithm.algo

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
3+
FONCTION tri-bulle tableau de 1 a n
4+
5+
DECLARER Taille = taille du tableau
6+
DECLARER temporaire = 0
7+
8+
POUR i allant de la taille du tableau-1 à 1
9+
10+
POUR j allant de 1 à taille du tableau -i
11+
12+
COMPARER 2 valeurs qui se suivent
13+
14+
SI Tab[j-1] > Tab[j]
15+
16+
ALORS temporaire = Tab[Tab-1]
17+
Tab[j-1] = Tab[j]
18+
Tab[j] = temporaire
19+
20+
FIN SI
21+
22+
FIN POUR
23+
24+
AFFICHER tableau
25+
26+
FIN

tri-a-bulle-normal/src/Main.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import java.util.Arrays;
2+
import java.util.Random;
3+
4+
public class Main {
5+
public static float echanges = 0;
6+
public static float comparaisons = 0;
7+
public static float affectations = 0;
8+
9+
public static void main(String[] args) {
10+
// write your code here
11+
// Clear console
12+
System.out.print("\033[H\033[2J");
13+
14+
// Tableau de test
15+
// int[] tab = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
16+
17+
// System.out.println("Tableau de test : " + Arrays.toString(tri_bulleN(tab)));
18+
19+
stat(10,20,5,10);
20+
21+
22+
}
23+
24+
public static int[] tri_bulleN(int[] tab) {
25+
echanges = 0;
26+
comparaisons = 0;
27+
affectations = 0;
28+
int taille = tab.length;
29+
int tmp = 0;
30+
for (int i = 0; i < taille; i++) {
31+
32+
for (int j = 1; j < (taille - i); j++) {
33+
if (tab[j - 1] > tab[j]) {
34+
tmp = tab[j - 1];
35+
tab[j - 1] = tab[j];
36+
tab[j] = tmp;
37+
38+
echanges++;
39+
comparaisons++;
40+
affectations += 3;
41+
}
42+
comparaisons++;
43+
}
44+
comparaisons++;
45+
}
46+
47+
48+
//System.out.println("Il y a eu " + comparaisons + " comparaisons, " + echanges + " échange et " + affectations + " affectations");
49+
return tab;
50+
}
51+
52+
public static void stat(int min,int max, int step, int nbr) {
53+
int i;
54+
comparaisons = 0;
55+
echanges = 0;
56+
affectations = 0;
57+
for ( i = 1 ; i <= nbr ; i++) {
58+
int Tab[] =new Random().ints(min).toArray();
59+
tri_bulleN(Tab);
60+
}
61+
if (min < max && i>nbr) {
62+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectations/nbr);
63+
stat((min+step),max,step,nbr);
64+
} else {
65+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectations/nbr);
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)