Diagramme de démonstration de l'algorithme de tri à bulles :
public static void bubbleSort(int[] array) { //Choisissez l'une des deux options suivantes///Méthode 1 for (int i = array.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (array[j] > array[j + 1]) { Sort.swap(array, j, j + 1);//Échange j et j+1 } } } / / /Méthode 2 for(int i=0;i<array.length;i++){ for(int j=0;j<array.length-1-i;j++){ if(array[j]>array[j+1]) { Sort.swap(array, j, j+1);//Échanger j et j+1 } } } }Ce qui précède représente l'intégralité du contenu de cet article. J'espère qu'il sera utile à tout le monde pour comprendre l'algorithme de tri à bulles en Java.