package day3;
public class BubbleSort {
public BubbleSort(int[] a) {
int temp = 0;
for(int i=a.length-1; i>0; i--){
for(int j=0; j<i; j++){
if(a[j]>a[j+1]){
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
System.out.printf("\n선택 정렬 %d 단계 : ", (i-8)*(-1));
for(int j=0; j<a.length-1; j++)
System.out.printf("%3d ", a[j]);
}
}
public static void main(String[] args) {
int[] a = {69,10,30,2,16,8,31,22};
BubbleSort sort = new BubbleSort(a);
}
}
'Java > 자료구조와 알고리즘' 카테고리의 다른 글
redixSort 에제 (0) | 2017.09.08 |
---|---|
MergeSort 예제 (0) | 2017.09.08 |
Selection Sort (0) | 2017.09.07 |
Quick Sort 소스 (0) | 2017.09.07 |
TreeMap 으로 순서정렬 알고리즘 (0) | 2017.09.07 |