Skip to content

Instantly share code, notes, and snippets.

@rskupnik
Created December 2, 2017 11:29
Show Gist options
  • Save rskupnik/ae98f6487a865af9314cdc620e9ce335 to your computer and use it in GitHub Desktop.
Save rskupnik/ae98f6487a865af9314cdc620e9ce335 to your computer and use it in GitHub Desktop.
Dla niestacjonarnych leniów
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