Selection sort

Similar to bubble sort, selection sort also divides an input list into two parts—a sublist of items already sorted in the left side and a sublist of items remaining to be sorted in the rest of the list. If we are going to sort the input list in ascending order, the lowest items will be in the leftmost position in the input list. These are the steps to perform a selection sort on a given input list:

  1. Find the first index of the unsorted sublist and mark it as minIndex. If it's the first sorting iteration, the index should be 0.
  2. Iterate through the elements of the unsorted sublist, starting at its first element (the first time, it should be index 1 through n - 1) and compare the current value element in the iteration with the ...

Get C++ Data Structures and Algorithms now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.