Skip to content

Commit 73b48e8

Browse files
authored
Merge pull request #7 from CodingFactory-Repos/Feature/Tri-a-bulles-optimise-Recursif
🔂 - Add Recursif
2 parents 7d2a902 + ff55875 commit 73b48e8

5 files changed

Lines changed: 62 additions & 34 deletions

File tree

Tri-a-bulles-optimise/Algorithm-Iteratif.algo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ FONCTION ENTIER TriBulle( tableau : INT )
2929
FIN POUR
3030
FIN TANT QUE
3131

32-
ECRIRE tableau
3332
RETOURNER tableau
3433

3534
FIN
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Tri à bulles optimisé
2+
FONCTION ENTIER TriBulle( tableau : INT )
3+
// Définir les variables
4+
VARIABLE
5+
INT: n
6+
INT: i
7+
INT: temp
8+
// Début de l'algorithme
9+
DEBUT
10+
// Initialisation
11+
n ◄- TAILLE(tableau)
12+
13+
// On parcourt le tableau
14+
POUR i DE 1 A n FAIRE
15+
// On compare les éléments suivants
16+
SI tableau[i] > tableau[i+1] ALORS
17+
// On échange les valeurs
18+
temp ◄- tableau[i]
19+
tableau[i] ◄- tableau[i+1]
20+
tableau[i+1] ◄- temp
21+
RETOURNER APPELER TriBulle(tableau)
22+
FIN SI
23+
FIN POUR
24+
25+
RETOURNER tableau
26+
FIN
27+
FIN FONCTION

Tri-a-bulles-optimise/Algorithm-Recursive.algo

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void main(String[] args) {
1414
// Tableau de test
1515
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) };
1616

17-
triBulle(tableau);
17+
System.out.println(Arrays.toString(triBulle(tableau)));
1818
}
1919

2020
public static int[] triBulle(int [] tableau) {
@@ -32,8 +32,6 @@ public static int[] triBulle(int [] tableau) {
3232
}
3333
}
3434

35-
System.out.println(Arrays.toString(tableau));
36-
3735
return tableau;
3836
}
3937
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Import Arrays
2+
import java.util.Arrays;
3+
import java.util.Random;
4+
5+
public class Recursif {
6+
7+
public static void main(String[] args) {
8+
// write your code here
9+
// Clear console
10+
System.out.print("\033\033");
11+
12+
Random rand = new Random();
13+
14+
// 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)));
18+
}
19+
20+
public static int[] triBulle(int [] tableau) {
21+
int n = tableau.length;
22+
23+
for (int i = 0; i < n - 1; i++) {
24+
if (tableau[i] > tableau[i + 1]) {
25+
int temp = tableau[i];
26+
tableau[i] = tableau[i + 1];
27+
tableau[i + 1] = temp;
28+
return triBulle(tableau);
29+
}
30+
}
31+
32+
return tableau;
33+
}
34+
}

0 commit comments

Comments
 (0)