Default comparator function used for sorting
first element to compare
second element to compare
a negative number if a < b, 0 if a = b, a positive number if a > b
Private Readonly defaultPrivate Readonly sizePrivate Readonly valuesStatic defaultStatic sortSorts the array using the SelectionSort algorithm. Static method, no need to instantiate class
the array to be sorted
the comparator function used for sorting, defaults to numerical comparison
Default comparator function used for sorting
first element to compare
second element to compare
a negative number if a < b, 0 if a = b, a positive number if a > b
a new array with the elements sorted
Generated using TypeDoc
SelectionSort is a simple sorting algorithm that divides the input array into a sorted and an unsorted region. It repeatedly selects the smallest (or largest) element from the unsorted region and moves it to the end of the sorted region.
The algorithm maintains two subarrays:
In every iteration, the minimum element from the unsorted subarray is picked and moved to the sorted subarray.
The time complexity is O(n^2) in all cases (best, average, and worst), making it inefficient for large datasets. However, it performs well on small lists and requires minimal memory writes compared to other sorting algorithms.
Example
Example