Created
April 12, 2017 22:52
-
-
Save artlovan/c39d9842964c64fed9eb9cffb38f585a to your computer and use it in GitHub Desktop.
BubbleSort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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