Created
August 8, 2020 00:28
-
-
Save goyuninfo/0cd26f4f66404d5bf441a01a29134a4e 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
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