Skip to content

Commit

Permalink
Merge pull request kodecocodes#812 from laurentaylormarshall/swift4.2…
Browse files Browse the repository at this point in the history
…-migration

[Swift 4.2] Updated QuickSort
  • Loading branch information
richard-ash authored Aug 29, 2020
2 parents 3d7e20a + d3de867 commit 82494bf
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 34 deletions.
5 changes: 0 additions & 5 deletions Quicksort/Quicksort.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//: Playground - noun: a place where people can play

// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif

import Foundation

// *** Simple but inefficient version of quicksort ***
Expand Down
7 changes: 0 additions & 7 deletions Quicksort/Tests/QuicksortTests.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import XCTest

class QuicksortTests: XCTestCase {
func testSwift4() {
// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif
}

func testQuicksort() {
checkSortAlgorithm(quicksort)
}
Expand Down
1 change: 0 additions & 1 deletion Quicksort/Tests/SortingTestHelpers.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import XCTest

func randomArray(_ size: Int) -> [Int] {
Expand Down
10 changes: 7 additions & 3 deletions Quicksort/Tests/Tests-Quicksort.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0900;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Swift Algorithm Club";
TargetAttributes = {
7B2BBC7F1C779D720067B71D = {
Expand Down Expand Up @@ -149,12 +149,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -187,7 +189,7 @@
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -203,12 +205,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand All @@ -234,7 +238,7 @@
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,7 +10,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -31,7 +30,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
14 changes: 6 additions & 8 deletions Slow Sort/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ We can decompose the problem of sorting n numbers in ascending order into
Here is an implementation of slow sort in Swift:

```swift
public func slowsort(_ i: Int, _ j: Int) {
if i>=j {
return
}
func slowSort(_ i: Int, _ j: Int, _ numberList: inout [Int]) {
guard if i < j else { return }
let m = (i+j)/2
slowsort(i,m)
slowsort(m+1,j)
slowSort(i, m, &numberList)
slowSort(m+1, j, &numberList)
if numberList[j] < numberList[m] {
let temp = numberList[j]
numberList[j] = numberList[m]
numberList[m] = temp
}
slowsort(i,j-1)
slowSort(i, j-1, &numberList)
}
```

Expand All @@ -47,4 +45,4 @@ public func slowsort(_ i: Int, _ j: Int) {

*Written for Swift Algorithm Club by Lukas Schramm*

(used the Insertion Sort Readme as template)
(used the Insertion Sort Readme as template)
13 changes: 6 additions & 7 deletions Slow Sort/SlowSort.playground/Sources/SlowSort.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Foundation

public func slowsort(_ i: Int, _ j: Int, _ numberList: inout [Int]) {
if i>=j {
return
}
public func slowSort(_ i: Int, _ j: Int, _ numberList: inout [Int]) {
guard i < j else { return }

let m = (i+j)/2
slowsort(i, m, &numberList)
slowsort(m+1, j, &numberList)
slowSort(i, m, &numberList)
slowSort(m+1, j, &numberList)
if numberList[j] < numberList[m] {
let temp = numberList[j]
numberList[j] = numberList[m]
numberList[m] = temp
}
slowsort(i, j-1, &numberList)
slowSort(i, j-1, &numberList)
}

0 comments on commit 82494bf

Please sign in to comment.