정렬 알고리즘 예제

By | 1월 8, 2010

* 버블 정렬 예제 (Java)

int[] arr = {8,6,4,2,5,1,3,7};

for(int i=(arr.length -1); i>0; i--){
 for(int j=0; j<i; j++){
  int temp = 0;
  if(arr[j] > arr[j+1]){
   temp = arr[j];
   arr[j] = arr[j+1];
   arr[j+1]= temp;
  }
 }
}

System.out.println(java.util.Arrays.toString(arr));

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments