O'Reilly logo

C++ Data Structures and Algorithms by Wisnu Anggoro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required