Skip to content

Instantly share code, notes, and snippets.

@keehyun2
Last active January 24, 2018 12:02
Show Gist options
  • Save keehyun2/4a35ce0af48f245618b7f525abc84656 to your computer and use it in GitHub Desktop.
Save keehyun2/4a35ce0af48f245618b7f525abc84656 to your computer and use it in GitHub Desktop.
bubbleSort
void bubbleSort(int[] arr){
for(int i = arr.length - 1; i > 0; i --)// main loop, i 는 (배열의 길이 - 1) 에서 1까지 1씩 감소
for(int j =0; j < i ; j++) // j 는 0부터 i 까지 1씩 증가하며 반복
if(arr[j] > arr[j+1]) swap(arr, j, j+1); // index 가 작은 원소가 클경우 교환
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment