@@ -0,0 +1,1235 @@
+package com.dev.namhoai.sort;%0A%0Apublic class BubbleSort %7B%0A%0A    public static %3CT extends Comparable%3E void sort(T%5B%5D a) %7B%0A        for (int i = 0; i %3C a.length; i++) %7B%0A            //last i elements are already in sorted%0A            for (int j = 1; j %3C a.length - i; j++) %7B%0A                if (a%5Bj - 1%5D.compareTo(a%5Bj%5D) %3E 0) %7B%0A                    T temp = a%5Bj - 1%5D; //swap%0A                    a%5Bj - 1%5D = a%5Bj%5D;%0A                    a%5Bj%5D = temp;%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     * This is simple version of in-place, stable bubble sort, whose best case is O(n) and worst Case O(n%5E2);%0A     */%0A    public static void sortSimple(int%5B%5D a) %7B%0A        for (int i = 0; i %3C a.length; i++) %7B%0A            boolean sorted = true; //flag to check if any swapping made%0A            // last elements sorted%0A            for (int j = 1; j %3C a.length - i; j++) %7B%0A                if (a%5Bj%5D %3C a%5Bj - 1%5D) %7B //swap%0A                    int temp = a%5Bj - 1%5D;%0A                    a%5Bj - 1%5D = a%5Bj%5D;%0A                    a%5Bj%5D = temp;%0A                    sorted = false;%0A                %7D%0A            %7D%0A%0A            // if any swapping has not occurred in the last iteration, we can say it is sorted now%0A            if (sorted) break;%0A        %7D%0A    %7D%0A%7D

Add Bubble Sort in Java