Skip to content

Instantly share code, notes, and snippets.

@keehyun2
Last active January 24, 2018 12:02
Show Gist options
  • Save keehyun2/597d0baf70a3c18cee806da4f9eee56d to your computer and use it in GitHub Desktop.
Save keehyun2/597d0baf70a3c18cee806da4f9eee56d to your computer and use it in GitHub Desktop.
void selectionSort(int[] arr){
for(int i = arr.length - 1; i > 0; i --) {
int maxIndex = 0 ; // 배열 원소중 max 값의 index를 저장할 변수
for(int j = 1; j <= i ; j++)
if(arr[j] > arr[maxIndex]) maxIndex = j;
swap(arr, maxIndex, i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment