Demonstrationsdiagramm des Blasensortierungsalgorithmus:
public static void bubbleSort(int[] array) { //Wählen Sie eine der nächsten beiden Optionen///Methode 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);//Exchange j und j+1 } } } / / /Methode 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);//Swap j und j+1 } } } }Das Obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, er wird jedem beim Verständnis des Blasensortierungsalgorithmus in Java helfen.