Skip to content

Bubble Sort

public class BubbleSort {
    public static void bubbleSort(ArrayList<Integer> array) {
        boolean swapped = true;

        while (swapped) {
            swapped = false;
            for (int i = 0; i <= array.size(); i++) {
                if (array[i] > array[i + 1]) {
                    swapped = true;
                    int aux = array[i];
                    array[i] = array[i + 1];
                    array[i + 1] = aux;
                }
            }
        }
    }
}