Created
May 27, 2016 04:13
-
-
Save onlylemi/abf17d91eed0f9cce84e9a998c536c4b to your computer and use it in GitHub Desktop.
【算法】选择排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void sort(int[] arr) { | |
int min, k; | |
for (int i = 0; i < arr.length - 1; i++) { | |
min = arr[i]; | |
k = i; | |
for (int j = i + 1; j < arr.length; j++) { | |
if (arr[j] < min) { | |
k = j; | |
min = arr[j]; | |
} | |
} | |
int temp = arr[i]; | |
arr[i] = arr[k]; | |
arr[k] = temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment