File tree Expand file tree Collapse file tree 1 file changed +1
-19
lines changed
Selection Sort/SelectionSort.playground/Sources Expand file tree Collapse file tree 1 file changed +1
-19
lines changed Original file line number Diff line number Diff line change 33/// - Parameter array: array of elements that conform to the Comparable protocol
44/// - Returns: an array in ascending order
55public func selectionSort< T: Comparable > ( _ array: [ T ] ) -> [ T ] {
6- guard array. count > 1 else { return array }
7-
8- var a = array
9- for x in 0 ..< a. count - 1 {
10-
11- // Find the lowest value in the rest of the array.
12- var lowest = x
13- for y in x + 1 ..< a. count {
14- if a [ y] < a [ lowest] {
15- lowest = y
16- }
17- }
18-
19- // Swap the lowest value with the current array index.
20- if x != lowest {
21- a. swapAt ( x, lowest)
22- }
23- }
24- return a
6+ return insertionSort ( array, < )
257}
268
279/// Performs the Selection sort algorithm on a array using the provided comparisson method
You can’t perform that action at this time.
0 commit comments