Created
November 2, 2015 19:35
-
-
Save mkoskinen/b4673c6d630a9df90181 to your computer and use it in GitHub Desktop.
This file contains 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 Kymppi { | |
private static void pieninEnsimmaiseksi(int[] taulu, int alku, int loppu) { | |
int min = Integer.MAX_VALUE; | |
int min_position = -1; | |
for (int i = alku; i <= loppu; i++) { | |
if (taulu[i] < min) { | |
min = taulu[i]; | |
min_position = i; | |
} | |
} | |
//System.out.println("DEBUG: min == "+ min +", min_position == " + min_position); | |
// Read the first value to memory, so it is not lost | |
int orig_value = taulu[alku]; | |
taulu[alku] = taulu[min_position]; | |
taulu[min_position] = orig_value; | |
} | |
public static void main (String[] args) { | |
int[] taulu = {2,5,1,8,3,9,0,4,6,7}; | |
for (int i = 0; i < taulu.length; i++) | |
pieninEnsimmaiseksi(taulu, i, taulu.length - 1); | |
for (int i = 0; i < taulu.length; i++) | |
System.out.print(taulu[i]); | |
System.out.println(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment