Ask Question

Write a method minToFront that takes an ArrayList of integers as a parameter and that moves the minimum value in the list to the front, otherwise preserving the order of the elements. For example, if a variable called list stores the following values: {3, 8, 92, 4, 2, 17, 9} and you make this call: minToFront (list); it should store the following values after the call: {2, 3, 8, 92, 4, 17, 9} You may assume that the list stores at least one value.

+3
Answers (1)
  1. 4 April, 16:36
    0
    The key to this algorithm is to compare each value with its previous value. If the previous value is larger than the current value, change currentVal = previous value and previousVal = currentVal (of course u will need a tempVal to store one of the value). The program should loop from first value til the very end and should only run once.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a method minToFront that takes an ArrayList of integers as a parameter and that moves the minimum value in the list to the front, ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers