2014년 2월 27일 목요일

성능개선 정렬 알고리즘 ( Bubble Sort )

public class SearchUtil {

private static void bubbleSort(int[] source){
int length = source.length;
for(int i=0; i< length-1; ++i){
for(int j=0; j< length - 1 - i; ++j){
if(source[j] > source[j+1]){
int tmp = source[j];
source[j] = source[j+1];
source[j+1] = tmp;
}
}
}
}

private static void bubbleSort(ArrayList<Integer> source){
int length = source.size();
for(int i=0; i< length-1; ++i){
for(int j=0; j< length - 1 - i; ++j){
if(source.get(j) > source.get(j+1)){
int tmp = source.get(j);
source.set(j, source.get(j+1));
source.set(j+1, tmp);
}
}
}
}
}







댓글 없음:

댓글 쓰기