Created
December 2, 2017 11:29
-
-
Save rskupnik/ae98f6487a865af9314cdc620e9ce335 to your computer and use it in GitHub Desktop.
Dla niestacjonarnych leniów
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
2: | |
public static int whereIsMaxValue(int[] table) { | |
int max; | |
int maxIndex = -1; | |
for (int i = 0; i < table.length; i++) { | |
if (table[i] > max) { | |
max = table[i]; | |
maxIndex = i; | |
} | |
} | |
return maxIndex; | |
} | |
3: | |
public static int whereIsMinValue(int[] table) { | |
int max = Integer.MAX_VALUE; | |
int maxIndex = -1; | |
for (int i = 0; i < table.length; i++) { | |
if (table[i] < max) { | |
max = table[i]; | |
maxIndex = i; | |
} | |
} | |
return maxIndex; | |
} | |
public static void exchangeMinMaxValues(int[] table) { | |
int maxIndex = whereIsMaxValue(table); | |
int minIndex = whereIsMinValue(table); | |
int maxValue = table[maxIndex]; | |
int minValue = table[minIndex]; | |
table[maxIndex] = minValue; | |
table[minIndex] = maxValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment