Skip to content

Commit 82494bf

Browse files
authored
Merge pull request kodecocodes#812 from laurentaylormarshall/swift4.2-migration
[Swift 4.2] Updated QuickSort
2 parents 3d7e20a + d3de867 commit 82494bf

File tree

7 files changed

+20
-34
lines changed

7 files changed

+20
-34
lines changed

Diff for: Quicksort/Quicksort.playground/Contents.swift

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
//: Playground - noun: a place where people can play
22

3-
// last checked with Xcode 9.0b4
4-
#if swift(>=4.0)
5-
print("Hello, Swift 4!")
6-
#endif
7-
83
import Foundation
94

105
// *** Simple but inefficient version of quicksort ***

Diff for: Quicksort/Tests/QuicksortTests.swift

-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import XCTest
22

33
class QuicksortTests: XCTestCase {
4-
func testSwift4() {
5-
// last checked with Xcode 9.0b4
6-
#if swift(>=4.0)
7-
print("Hello, Swift 4!")
8-
#endif
9-
}
10-
114
func testQuicksort() {
125
checkSortAlgorithm(quicksort)
136
}

Diff for: Quicksort/Tests/SortingTestHelpers.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import Foundation
21
import XCTest
32

43
func randomArray(_ size: Int) -> [Int] {

Diff for: Quicksort/Tests/Tests-Quicksort.xcodeproj/project.pbxproj

+7-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
isa = PBXProject;
8787
attributes = {
8888
LastSwiftUpdateCheck = 0720;
89-
LastUpgradeCheck = 0900;
89+
LastUpgradeCheck = 1000;
9090
ORGANIZATIONNAME = "Swift Algorithm Club";
9191
TargetAttributes = {
9292
7B2BBC7F1C779D720067B71D = {
@@ -149,12 +149,14 @@
149149
CLANG_WARN_BOOL_CONVERSION = YES;
150150
CLANG_WARN_COMMA = YES;
151151
CLANG_WARN_CONSTANT_CONVERSION = YES;
152+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
152153
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
153154
CLANG_WARN_EMPTY_BODY = YES;
154155
CLANG_WARN_ENUM_CONVERSION = YES;
155156
CLANG_WARN_INFINITE_RECURSION = YES;
156157
CLANG_WARN_INT_CONVERSION = YES;
157158
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
159+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
158160
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
159161
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
160162
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -187,7 +189,7 @@
187189
SDKROOT = macosx;
188190
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
189191
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
190-
SWIFT_VERSION = 4.0;
192+
SWIFT_VERSION = 4.2;
191193
};
192194
name = Debug;
193195
};
@@ -203,12 +205,14 @@
203205
CLANG_WARN_BOOL_CONVERSION = YES;
204206
CLANG_WARN_COMMA = YES;
205207
CLANG_WARN_CONSTANT_CONVERSION = YES;
208+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
206209
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
207210
CLANG_WARN_EMPTY_BODY = YES;
208211
CLANG_WARN_ENUM_CONVERSION = YES;
209212
CLANG_WARN_INFINITE_RECURSION = YES;
210213
CLANG_WARN_INT_CONVERSION = YES;
211214
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
215+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
212216
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
213217
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
214218
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -234,7 +238,7 @@
234238
SDKROOT = macosx;
235239
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
236240
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
237-
SWIFT_VERSION = 4.0;
241+
SWIFT_VERSION = 4.2;
238242
};
239243
name = Release;
240244
};

Diff for: Quicksort/Tests/Tests-Quicksort.xcodeproj/xcshareddata/xcschemes/Tests-Quicksort.xcscheme

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "1000"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -10,7 +10,6 @@
1010
buildConfiguration = "Debug"
1111
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1212
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13-
language = ""
1413
shouldUseLaunchSchemeArgsEnv = "YES">
1514
<Testables>
1615
<TestableReference
@@ -31,7 +30,6 @@
3130
buildConfiguration = "Debug"
3231
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3332
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
34-
language = ""
3533
launchStyle = "0"
3634
useCustomWorkingDirectory = "NO"
3735
ignoresPersistentStateOnLaunch = "NO"

Diff for: Slow Sort/README.markdown

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@ We can decompose the problem of sorting n numbers in ascending order into
1717
Here 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)

Diff for: Slow Sort/SlowSort.playground/Sources/SlowSort.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import 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
}

0 commit comments

Comments
 (0)