Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

minToFront

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

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.