Skip to content

Instantly share code, notes, and snippets.

@yaboong
Created February 18, 2018 20:08
Show Gist options
  • Save yaboong/d04c3739a03a41e949d4a02d380c2b7f to your computer and use it in GitHub Desktop.
Save yaboong/d04c3739a03a41e949d4a02d380c2b7f to your computer and use it in GitHub Desktop.
Bubble Sort
import java.util.Arrays;
/**
* Created by yaboong on 2018. 2. 14..
*/
public class BubbleSort {
public static void bubbleSort(int[] arr) {
int temp = 0;
for(int i = 0; i < arr.length; i++) {
for(int j= 1 ; j < arr.length-i; j++) {
if(arr[j]<arr[j-1]) {
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}
}
}
System.out.println(Arrays.toString(arr));
}
public static void main(String[] args) {
bubbleSort(new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment