Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Created May 30, 2021 07:07
Show Gist options
  • Save lifeparticle/668f613231103e55521dbb51b4149eac to your computer and use it in GitHub Desktop.
Save lifeparticle/668f613231103e55521dbb51b4149eac to your computer and use it in GitHub Desktop.
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