File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Selection Sort/SelectionSort.playground/Sources Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 1+ /// Performs the Selection sort algorithm on a array
2+ ///
3+ /// - Parameter array: array of elements that conform to the Comparable protocol
4+ /// - Returns: an array in ascending order
15public func selectionSort< T: Comparable > ( _ array: [ T ] ) -> [ T ] {
26 guard array. count > 1 else { return array }
37
@@ -20,6 +24,12 @@ public func selectionSort<T: Comparable>(_ array: [T]) -> [T] {
2024 return a
2125}
2226
27+ /// Performs the Selection sort algorithm on a array using the provided comparisson method
28+ ///
29+ /// - Parameters:
30+ /// - array: array of elements that conform to the Comparable protocol
31+ /// - isLowerThan: returns true if the two provided elements are in the correct order
32+ /// - Returns: a sorted array
2333public func selectionSort< T> ( _ array: [ T ] , _ isLowerThan: ( T , T ) -> Bool ) -> [ T ] {
2434 guard array. count > 1 else { return array }
2535
You can’t perform that action at this time.
0 commit comments