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.

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

       }

   }

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.