This figure should be helpful :
Then to answer your question, what would you do on paper ?
- Create and initialize the min value at
tenIntArray[0]
- 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]
) - Loop through the elements of your array
- 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
- You're done
Writing the algorithm should be straightforward now.
No comments:
Post a Comment