Created
May 30, 2021 07:07
-
-
Save lifeparticle/668f613231103e55521dbb51b4149eac to your computer and use it in GitHub Desktop.
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 Main { | |
public static void main (String args[]) { | |
selectionSort(new int [] {1, 4, 7, 10, 2}); | |
} | |
public static void selectionSort(int[] arr) { | |
int tmp, minIndex; | |
for (int i = 0; i < arr.length - 1; ++i) { | |
minIndex = i; | |
for (int j = i + 1; j < arr.length; ++j) { | |
if (arr[minIndex] > arr[j]) { | |
minIndex = j; | |
} | |
} | |
tmp = arr [i]; | |
arr [i] = arr [minIndex]; | |
arr [minIndex] = tmp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment