This is a beta version of Practice-It. Give us feedback

logo Practice-It logo

minToFront

Language/Type: Java arrays
Author: Stuart Reges (on 2020/10/06)

Write a static method called minToFront that takes an array of integers as a parameter and that moves the minimum value in the list to the front by swapping its position with whatever is currently at the front of the list. For example, if a variable called list stores the following values:

            [3, 8, 92, 4, 2, 17, 9]
        

and you make the following call:

            minToFront(list);
        

The value 2 is the minimum, so the list should store the following values after the call:

            [2, 8, 92, 4, 3, 17, 9]
        

Notice that the value 3 which used to be at the front of the list is now at index 4 where the value 2 was before. If there is more than one occurrence of the minimum value, your method should move the first occurrence to the front of the list. If the minimum value is already at the front of the array or if the array is empty, then the array should be unchanged after the method executes.

You may not construct any extra data structures to solve this problem (not even a string).

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.