Skip to content

Commit 72dd831

Browse files
committed
☕️ - Creation of the code from the algorithm
1 parent ca240da commit 72dd831

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Import Arrays
2+
import org.jetbrains.annotations.NotNull;
3+
4+
import java.util.Arrays;
5+
6+
public class Main {
7+
8+
public static void main(String[] args) {
9+
// write your code here
10+
// Clear console
11+
System.out.print("\033[H\033[2J");
12+
13+
// Tableau de test
14+
int[] tableau = { 1, 3, 7, 2, 6, 4, 5, 8, 10, 9 };
15+
16+
System.out.println("Tableau de test : "+Arrays.toString(triBulle(tableau)));
17+
18+
}
19+
20+
public static int[] triBulle(int @NotNull [] tableau) {
21+
int n = tableau.length;
22+
boolean echange = true;
23+
while (echange) {
24+
echange = false;
25+
for (int i = 0; i < n - 1; i++) {
26+
if (tableau[i] > tableau[i + 1]) {
27+
int temp = tableau[i];
28+
tableau[i] = tableau[i + 1];
29+
tableau[i + 1] = temp;
30+
echange = true;
31+
}
32+
}
33+
}
34+
35+
// Return le resultat
36+
return tableau;
37+
}
38+
}

0 commit comments

Comments
 (0)