package com.naughtyzombie.sorting.bubble;

/**
 * Created by pram on 24/06/2015.
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] input = {4, 2, 9, 6, 23, 12, 34, 0, 1, 4, 6, 3};
        BubbleSort bs = new BubbleSort();
        bs.bubbleSort(input);
    }

    private void bubbleSort(int[] input) {
        int n = input.length;
        int k;
        for (int m = n; m >= 0; m--) {
            for (int i=0; i < n -1; i++) {
                k = i + 1;
                if (input[i] > input[k]) {
                    swapNumbers(i,k,input);
                }
            }
            printNumbers(input);
        }
    }

    private void printNumbers(int[] input) {
        for (int i = 0; i < input.length; i++) {
            int out = input[i];
            System.out.print(out + ", ");
        }
        System.out.print("\n");
    }

    private void swapNumbers(int i, int k, int[] input) {
        int temp;
        temp = input[i];
        input[i]  = input[k];
        input[k] = temp;
    }


}

@@ -651,24 +651,444 @@
      %7D%0A    %7D
+%0A    %0A    //This is a cleaner implementation%0A    private void sort(int%5B%5D input) %7B%0A        int n = input.length;%0A%0A        for (int m = n; m %3E= 0; m--) %7B%0A            for (int i = 0; i %3C n - 1; i++) %7B%0A                if (input%5Bi%5D %3E input %5Bi + 1%5D) %7B%0A                    int temp = input%5Bi%5D;%0A                    input%5Bi%5D = input%5Bi + 1%5D;%0A                    input%5Bi + 1%5D = temp;%0A                %7D%0A            %7D%0A        %7D%0A    %7D
 %0A%0A    privat

Update BubbleSort.java