Westonci.ca is your go-to source for answers, with a community ready to provide accurate and timely information. Our platform offers a seamless experience for finding reliable answers from a network of experienced professionals. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.
Sagot :
Answer:
Explanation:
Some of the information provided in the question was very counterintuitive which made understanding what was actually required very difficult. Regardless here is the function requested, it takes an array which is currently a type float but can be changed to whatever you need (since the actual type was missing in the question) and the min_or_max argument which takes in either a 0 to sort in descending order or a 1 to sort in ascending order. Finally, it prints out the entire array.
public void minMaxFunc(float[] input, int min_or_max) {
if (min_or_max == 0) {
int last = input.length - 1;
int middle = input.length / 2;
for (int i = 0; i <= middle; i++) {
float temp = input[i];
input[i] = input[last - i];
input[last - i] = temp;
}
} else if (min_or_max == 1) {
float temp = 0;
for (int i = 0; i < input.length; i++) {
for (int j = i+1; j < input.length; j++) {
if(input[i] > input[j]) {
temp = input[i];
input[i] = input[j];
input[j] = temp;
}
}
}
} else {
System.out.println("Wrong min or max value, enter 1 for max or 0 for min");
}
for (int x = 0; x < input.length; x++) {
System.out.println(input[x]);
}
}
We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Your questions are important to us at Westonci.ca. Visit again for expert answers and reliable information.