Created
October 31, 2010 16:29
-
-
Save Feuda/656795 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 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