At Westonci.ca, we connect you with experts who provide detailed answers to your most pressing questions. Start exploring now! Ask your questions and receive accurate answers from professionals with extensive experience in various fields on our platform. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

Let A be an array of n elements. Write a template function, minMaxFunc(...). which takes two parameters:

1. an unsorted array of type as an input parameter.
2. whether you want the minimum or maximum value

Use TWO stacks within the function to determine the minimum or maximum value and return that element
Stack 1 (LINKED LIST) holds values in ascending/descending order.
Stack 2 (ARRAY) is a "temporary" work stack as you insert values to keep them in order.

Once all values have been processed you must also print the values in the stack. In this question, you may use global constant SIZE-5. You must wrie all functions you call (PUSH, POP, PEEK, ISFULL ISEMPTY). You the first set then replace with the second set]: 4 1
13 3 2
1.1 4.1 8.1 5.2 2.3

Finally, with no changes to your function, instantiate your function for type char and report the outcome when using the first test data above.

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]);

       }

   }