Created
February 18, 2018 20:08
-
-
Save yaboong/d04c3739a03a41e949d4a02d380c2b7f to your computer and use it in GitHub Desktop.
Bubble Sort
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; | |
/** | |
* 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