Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in
Sequence
Bubble sort
Core exercise
Write triABulles(int[] tableau) that sorts the array in ascending order and returns it.
A workshop goes here: you write and run code in it. It requires JavaScript.
Starting code
Exercices.java
import java.util.Arrays;
public class Exercices {
public static void main(String[] args) {
int[] t = { 5, 1, 4, 2, 8 };
System.out.println(Arrays.toString(triABulles(t)));
}
public static int[] triABulles(int[] tableau) {
// TODO
return tableau;
}
}
The core exercise is validated in the workshop, which requires JavaScript.
Hint 1
Compare each pair of neighbours and swap them if they are out of order; start again until no swap takes place. Swapping requires a temporary variable.