Created
October 18, 2017 10:32
-
-
Save sasaki-shigeo/5cdddcc39c6829a7b7861dbdfeeb8189 to your computer and use it in GitHub Desktop.
Selection Sort Program in Java
This file contains hidden or 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 SelectionSort { | |
| static int[] data = { 5, 3, 8, 2, 9, 4, 1 }; | |
| public static void main(String[] args) { | |
| selection_sort(data); | |
| System.out.println(java.util.Arrays.toString(data)); | |
| } | |
| static void selection_sort(int[] data) { | |
| for (int k = 1; k < data.length; k++) { | |
| for (int i = 0; i < k; i++) { | |
| if (data[i] > data[k]) { | |
| int tmp = data[i]; | |
| data[i] = data[k]; | |
| data[k] = tmp; | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment