public static void bubbleSort(int[] arr) { if (arr == null || arr.length < 2) return;
for (int i = 0; i < arr.length; i++) { boolean isSwap = false; for (int j = 0; j < arr.length - i - 1; j++) { if (arr[j] > arr[j + 1]) { swap(arr, j, j + 1); isSwap = true; } } if (!isSwap) return; } }
|