Friday, September 19, 2014

Find smallest integer value in array list in Java without Arrays.sort

This figure should be helpful :
enter image description here
Then to answer your question, what would you do on paper ?
  1. Create and initialize the min value at tenIntArray[0]
  2. Create a variable to hold the index of the min value in the array and initialize it to 0 (because we said in 1. to initialize the min at tenIntArray[0])
  3. Loop through the elements of your array
  4. If you find an element inferior than the current min, update the minimum value with this element and update the index with the corresponding index of this element
  5. You're done
Writing the algorithm should be straightforward now.

No comments:

Post a Comment