Skip to content

Instantly share code, notes, and snippets.

@artlovan
Created April 12, 2017 22:52
Show Gist options
  • Save artlovan/c39d9842964c64fed9eb9cffb38f585a to your computer and use it in GitHub Desktop.
Save artlovan/c39d9842964c64fed9eb9cffb38f585a to your computer and use it in GitHub Desktop.
BubbleSort
import java.util.Arrays;
public class BubbleSort {
public static int[] data = new int[]{1, 8, 2, 7, 3, 4, 7, 6};
public static void main(String[] args) {
sort();
System.out.println(Arrays.toString(data));
}
public static void sort() {
for (int i = data.length - 1; i >= 0; i--) {
for (int j = 0; j < i; j++) {
if (data[j] > data[i]) {
int temp = data[j];
data[j] = data[i];
data[i] = temp;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment