Skip to content

Instantly share code, notes, and snippets.

@goyuninfo
Created August 8, 2020 00:28
Show Gist options
  • Save goyuninfo/0cd26f4f66404d5bf441a01a29134a4e to your computer and use it in GitHub Desktop.
Save goyuninfo/0cd26f4f66404d5bf441a01a29134a4e to your computer and use it in GitHub Desktop.
static void selectionSort(int[] lst) {
// get the length
int n = lst.length;
for (int i = 0; i < n; i++) {
int index = 0;
int smallest = lst[i];
for (int j = i; j < n; j++) {
if (lst[j] < smallest) {
smallest = lst[j];
index = j;
}
int temp = lst[i];
lst[i] = smallest;
lst[index] = temp;
}
}
System.out.println(Arrays.toString(lst));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment