| Objects | Type | Kind | Movement | Name |
| array to be sorted | int[ ] | varying | received & passed back |
arr |
| # of elements in array | int | varying | received | n |
| index of smallest element | int | varying | local | smallIndex |
| temporary for swapping | int | varying | local | temp |
| index counters | int, int | varying | local | pass, j |
void SelectionSort (int arr[], int n)
{
for (int pass = 0; pass < n-1; pass++)
{
// index of the smallest value in sublist
int smallIndex = pass;
// scan the sublist starting at pass+1
for (int j = pass+1; j < n; j++)
if (arr[j] < arr[smallIndex]) // found smaller
smallIndex = j;
// swap values, if needed
if (smallIndex != pass)
{
int temp = arr[pass];
arr[pass] = arr[smallIndex];
arr[smallIndex] = temp;
} // end swap
} // end for
} // end SelectionSort