@@ -0,0 +1,1331 @@
+import java.io.*;%0Aimport java.util.*;%0A%0Aclass BubbleSort %7B%0A%0A    public int%5B%5D array;%0A    public int swaps;%0A%0A    public BubbleSort(int%5B%5D array) %7B%0A        this.array = array;%0A        this.swaps = 0;%0A    %7D%0A%0A    public void sort() %7B%0A        int traversalSwaps = 0;%0A        do %7B%0A            traversalSwaps = 0;%0A            for (int i = 0; i %3C array.length - 1; i++) %7B%0A                if (array%5Bi%5D %3E array%5Bi + 1%5D) %7B%0A                    swap(i, i + 1);%0A                    traversalSwaps++;%0A                %7D%0A            %7D%0A        %7D while (traversalSwaps %3E 0);%0A    %7D%0A    %0A    private void swap(int index1, int index2) %7B%0A        int temp = array%5Bindex1%5D;%0A        array%5Bindex1%5D = array%5Bindex2%5D;%0A        array%5Bindex2%5D = temp;%0A        swaps++;%0A    %7D%0A%7D%0A%0Apublic class Solution %7B    %0A    public static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in);%0A        int n = in.nextInt();%0A        int%5B%5D array = new int%5Bn%5D; %0A        for(int i = 0; i %3C n; i++) %7B%0A            array%5Bi%5D = in.nextInt();%0A        %7D%0A%0A        BubbleSort bubbleSort = new BubbleSort(array);%0A        bubbleSort.sort();%0A        System.out.println(%22Array is sorted in %22 + bubbleSort.swaps + %22 swaps.%22);%0A        System.out.println(%22First Element: %22 + bubbleSort.array%5B0%5D);%0A        System.out.println(%22Last Element: %22 + bubbleSort.array%5Barray.length - 1%5D);%0A    %7D%0A%7D

Solve bubble sort