13


10/08/09 - Sorting an Array
We already know how to find the minimum value in an integer array.  We can sort an integer array by repeatedly finding the minimum value in the array and moving it towards the front of the array.  The first time through the array, we move the very smallest value to the first position in the array.  The next time through the array, we start at the second value (so the array we have to search for the minimum is one value shorter), and when we find the next smallest integer, we put that in the second position in the array.  We continue this process until we've put all the values in ascending (from smallest to largest) order.
The code below carries out this method of sorting an array (called a "selection" sort), and it breaks the different operations into different methods for clarity and simplicity.
Homework