[알고리즘] 버블정렬(BubbleSort)

ybw·2020년 12월 4일
0

버블정렬

  • 서로 인접한 두 원소를 검사하여 정렬하는 알고리즘

구현

코드(C++)

void bubble_sort(int list[], int n){
  int i, j, temp;

  for(i=n-1; i>0; i--){
    for(j=0; j<i; j++){
      if(list[j]<list[j+1]){
        temp = list[j];
        list[j] = list[j+1];
        list[j+1] = temp;
      }
    }
  }
}
profile
유병우

0개의 댓글