Selection Sort Program
Selection sort works as follows.
-
The array of values to be sorted is divided into two partitions:
the partition of sorted values and that of unsorted values.
-
In each step of selection sorting,
the smallest element in the unsorted partition
is picked up and is added to the end of the sorted partition.
-
The sorting proceeds until the elements in the unsorted partition
are exhausted.
-
We use floorIdx to designate the last element in the sorted
partition.
-
The array elements with indexes 0 through floorIdx
are in the partition of sorted values, and the rest in the patition
of unsorted values.
-
The first element of the unsorted partition
has array index floorIdx + 1.
-
Initially, no elements in the array belong to the sorted
partition, and hence floorIdx = -1.
-
While the smallest value in the unsorted partition is being slected,
the smallest value found so far is kept in minValue.
-
Sorted values are shown in purple, and unsorted values in green.
Source Code of the SelectSort Program
Source Code of the SelectSortG Program
(Graphical Version)
Back
Home