Skip to main content
Logo image

Section 22.5 Selection Sort

Selection Sort is one of the simplest sorting techniques. Suppose you wanted to sort from smallest to largest. Here are the steps:
  • Search through the list for the smallest element.
  • Swap the smallest element with the first element.
  • Continue/repeat with the reduced list (since the first element is already in its correct place).
The following visualization might help more clearly describe this process:

Activity 22.2.

Please implement the selection sort algorithm to sort the given array of numbers. Use a function to which you pass the unsorted array as well as its number of elements, and which sorts the array ’in place’, meaning that the unsorted array is replaced by the sorted array (rather than creating a sorted copy). You can use the given function printArray() to check whether your algorithm performed correctly.

admin.....open in new window

When you are done, please paste your code into the code submission box below: