카테고리 없음

2.알고리즘 기초 강의 버블 Sort

도꺠비 개발자 2022. 6. 19. 14:37
728x90

버블정렬은 옆에있는 값과 비교해서 더작은 값을 앞으로 보내는것이다

 int [] number = {10,3,2,6,8,12,5,7};


     int b = 0;
 for(int i = 0 ; i < number.length ; i++){
 for(int j=0; j < number.length - 1;j++) {

             if(number[j] > number[j+1]) {
              int tmp = number[j];
              number[j] = number[j+1];
              number[j+1] = tmp;
            }
     
         }

}
    구현하기는 가장쉬운 알고리즘이다 근대 가장 효율성이 떨어지는 알고리즘이다

728x90