Skip to content

Instantly share code, notes, and snippets.

@Feuda
Created October 31, 2010 16:29
Show Gist options
  • Save Feuda/656795 to your computer and use it in GitHub Desktop.
Save Feuda/656795 to your computer and use it in GitHub Desktop.
选择排序
public class Example13 {
public void selectionSort(int[] arr) {
int minIndex;
int t;
for (int i = 0; i < arr.length - 1; i++) {
minIndex = i;
for (int j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
t = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = t;
}
}
}
public class Example13_Test {
public static void main(String[] args) {
Example12 ob1 = new Example12();
Example13 ob2 = new Example13();
int[] array = new int[5];
ob1.input(array);
ob1.echo(array);
ob2.selectionSort(array);
ob1.echo(array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment