Selection Sort of N numbers: C

Advertisement:

Selection sort is a sorting technique which is inefficient on large list of elements. Its simple and easy to understand.

In selection sort, first we select one element and compare it with the rest of the elements. If the compared element is smaller than the selected element, then those numbers are sorted. This approach is continued till the last element in the array index.

The number of iterations is 1 less than the array size.
i.e., if the user enters array size as 5, then there will be 4 iterations.

Since the array index starts from 0, and we need not compare the last element in the array with any other elements, we iterate the outer loop from 0 to N-2.
We iterate the inner loop from i+1 till N-1.