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
1
5
public func selectionSort< T: Comparable > ( _ array: [ T ] ) -> [ T ] {
2
6
guard array. count > 1 else { return array }
3
7
@@ -20,6 +24,12 @@ public func selectionSort<T: Comparable>(_ array: [T]) -> [T] {
20
24
return a
21
25
}
22
26
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
23
33
public func selectionSort< T> ( _ array: [ T ] , _ isLowerThan: ( T , T ) -> Bool ) -> [ T ] {
24
34
guard array. count > 1 else { return array }
25
35
You can’t perform that action at this time.
0 commit comments