File tree Expand file tree Collapse file tree 2 files changed +12
-15
lines changed
SlowSort.playground/Sources Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -17,19 +17,17 @@ We can decompose the problem of sorting n numbers in ascending order into
1717Here is an implementation of slow sort in Swift:
1818
1919``` swift
20- public func slowsort (_ i : Int , _ j : Int ) {
21- if i>= j {
22- return
23- }
20+ func slowSort (_ i : Int , _ j : Int , _ numberList : inout [Int ]) {
21+ guard if i < j else { return }
2422 let m = (i+ j)/ 2
25- slowsort (i,m )
26- slowsort (m+ 1 ,j )
23+ slowSort (i, m, & numberList )
24+ slowSort (m+ 1 , j, & numberList )
2725 if numberList[j] < numberList[m] {
2826 let temp = numberList[j]
2927 numberList[j] = numberList[m]
3028 numberList[m] = temp
3129 }
32- slowsort (i,j- 1 )
30+ slowSort (i, j- 1 , & numberList )
3331}
3432```
3533
@@ -47,4 +45,4 @@ public func slowsort(_ i: Int, _ j: Int) {
4745
4846* Written for Swift Algorithm Club by Lukas Schramm*
4947
50- (used the Insertion Sort Readme as template)
48+ (used the Insertion Sort Readme as template)
Original file line number Diff line number Diff line change 11import Foundation
22
3- public func slowsort( _ i: Int , _ j: Int , _ numberList: inout [ Int ] ) {
4- if i>= j {
5- return
6- }
3+ public func slowSort( _ i: Int , _ j: Int , _ numberList: inout [ Int ] ) {
4+ guard i < j else { return }
5+
76 let m = ( i+ j) / 2
8- slowsort ( i, m, & numberList)
9- slowsort ( m+ 1 , j, & numberList)
7+ slowSort ( i, m, & numberList)
8+ slowSort ( m+ 1 , j, & numberList)
109 if numberList [ j] < numberList [ m] {
1110 let temp = numberList [ j]
1211 numberList [ j] = numberList [ m]
1312 numberList [ m] = temp
1413 }
15- slowsort ( i, j- 1 , & numberList)
14+ slowSort ( i, j- 1 , & numberList)
1615}
You can’t perform that action at this time.
0 commit comments