public class BubbleSort {

private int[] a;

public BubbleSort(int [] inputArray) {
a = inputArray;
}

public void bubbleSort() {
for (int out = a.length - 1; out > 1; out--) {
for (int in = 0; in < out; in++) {
if (a[in] > a[in + 1]) {
swap(in, in + 1);
}
}
}
}

private void swap(int one, int two) {
int temp = a[one];
a[one] = a[two];
a[two] = temp;
}
}

Categories: Data Structure