Skip to content

Commit 7077bc1

Browse files
committed
Updates the indentation of the code and updated project settings for Xcode 9
1 parent 028b898 commit 7077bc1

File tree

4 files changed

+48
-34
lines changed

4 files changed

+48
-34
lines changed

Heap Sort/HeapSort.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
extension Heap {
22
public mutating func sort() -> [T] {
33
for i in stride(from: (elements.count - 1), through: 1, by: -1) {
4-
elements.swapAt(0, i)
4+
elements.swapAt(0, i)
55
shiftDown(0, heapSize: i)
66
}
77
return elements
88
}
99
}
1010

1111
/*
12-
Sorts an array using a heap.
13-
Heapsort can be performed in-place, but it is not a stable sort.
14-
*/
12+
Sorts an array using a heap.
13+
Heapsort can be performed in-place, but it is not a stable sort.
14+
*/
1515
public func heapsort<T>(_ a: [T], _ sort: @escaping (T, T) -> Bool) -> [T] {
1616
let reverseOrder = { i1, i2 in sort(i2, i1) }
1717
var h = Heap(array: a, sort: reverseOrder)

Heap Sort/Tests/HeapSortTests.swift

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import XCTest
22

33
class HeapSortTests: XCTestCase {
4-
func testSwift4() {
5-
// last checked with Xcode 9.0b4
6-
#if swift(>=4.0)
7-
print("Hello, Swift 4!")
8-
#endif
9-
}
4+
func testSwift4() {
5+
// last checked with Xcode 9.0b4
6+
#if swift(>=4.0)
7+
print("Hello, Swift 4!")
8+
#endif
9+
}
10+
11+
func testSort() {
12+
var h1 = Heap(array: [5, 13, 2, 25, 7, 17, 20, 8, 4], sort: >)
13+
let a1 = h1.sort()
14+
XCTAssertEqual(a1, [2, 4, 5, 7, 8, 13, 17, 20, 25])
1015

11-
func testSort() {
12-
var h1 = Heap(array: [5, 13, 2, 25, 7, 17, 20, 8, 4], sort: >)
13-
let a1 = h1.sort()
14-
XCTAssertEqual(a1, [2, 4, 5, 7, 8, 13, 17, 20, 25])
15-
16-
let a1_ = heapsort([5, 13, 2, 25, 7, 17, 20, 8, 4], <)
17-
XCTAssertEqual(a1_, [2, 4, 5, 7, 8, 13, 17, 20, 25])
18-
19-
var h2 = Heap(array: [16, 14, 10, 8, 7, 8, 3, 2, 4, 1], sort: >)
20-
let a2 = h2.sort()
21-
XCTAssertEqual(a2, [1, 2, 3, 4, 7, 8, 8, 10, 14, 16])
22-
23-
let a2_ = heapsort([16, 14, 10, 8, 7, 8, 3, 2, 4, 1], <)
24-
XCTAssertEqual(a2_, [1, 2, 3, 4, 7, 8, 8, 10, 14, 16])
25-
26-
var h3 = Heap(array: [1, 2, 3, 4, 5, 6], sort: <)
27-
let a3 = h3.sort()
28-
XCTAssertEqual(a3, [6, 5, 4, 3, 2, 1])
29-
30-
let a3_ = heapsort([1, 2, 3, 4, 5, 6], >)
31-
XCTAssertEqual(a3_, [6, 5, 4, 3, 2, 1])
32-
}
16+
let a1_ = heapsort([5, 13, 2, 25, 7, 17, 20, 8, 4], <)
17+
XCTAssertEqual(a1_, [2, 4, 5, 7, 8, 13, 17, 20, 25])
18+
19+
var h2 = Heap(array: [16, 14, 10, 8, 7, 8, 3, 2, 4, 1], sort: >)
20+
let a2 = h2.sort()
21+
XCTAssertEqual(a2, [1, 2, 3, 4, 7, 8, 8, 10, 14, 16])
22+
23+
let a2_ = heapsort([16, 14, 10, 8, 7, 8, 3, 2, 4, 1], <)
24+
XCTAssertEqual(a2_, [1, 2, 3, 4, 7, 8, 8, 10, 14, 16])
25+
26+
var h3 = Heap(array: [1, 2, 3, 4, 5, 6], sort: <)
27+
let a3 = h3.sort()
28+
XCTAssertEqual(a3, [6, 5, 4, 3, 2, 1])
29+
30+
let a3_ = heapsort([1, 2, 3, 4, 5, 6], >)
31+
XCTAssertEqual(a3_, [6, 5, 4, 3, 2, 1])
32+
}
3333
}

Heap Sort/Tests/Tests.xcodeproj/project.pbxproj

+13-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
isa = PBXProject;
8787
attributes = {
8888
LastSwiftUpdateCheck = 0720;
89-
LastUpgradeCheck = 0820;
89+
LastUpgradeCheck = 0900;
9090
ORGANIZATIONNAME = "Swift Algorithm Club";
9191
TargetAttributes = {
9292
7B2BBC7F1C779D720067B71D = {
@@ -145,14 +145,20 @@
145145
CLANG_CXX_LIBRARY = "libc++";
146146
CLANG_ENABLE_MODULES = YES;
147147
CLANG_ENABLE_OBJC_ARC = YES;
148+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
148149
CLANG_WARN_BOOL_CONVERSION = YES;
150+
CLANG_WARN_COMMA = YES;
149151
CLANG_WARN_CONSTANT_CONVERSION = YES;
150152
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
151153
CLANG_WARN_EMPTY_BODY = YES;
152154
CLANG_WARN_ENUM_CONVERSION = YES;
153155
CLANG_WARN_INFINITE_RECURSION = YES;
154156
CLANG_WARN_INT_CONVERSION = YES;
157+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
158+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
155159
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
160+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
161+
CLANG_WARN_STRICT_PROTOTYPES = YES;
156162
CLANG_WARN_SUSPICIOUS_MOVE = YES;
157163
CLANG_WARN_UNREACHABLE_CODE = YES;
158164
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -191,14 +197,20 @@
191197
CLANG_CXX_LIBRARY = "libc++";
192198
CLANG_ENABLE_MODULES = YES;
193199
CLANG_ENABLE_OBJC_ARC = YES;
200+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
194201
CLANG_WARN_BOOL_CONVERSION = YES;
202+
CLANG_WARN_COMMA = YES;
195203
CLANG_WARN_CONSTANT_CONVERSION = YES;
196204
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
197205
CLANG_WARN_EMPTY_BODY = YES;
198206
CLANG_WARN_ENUM_CONVERSION = YES;
199207
CLANG_WARN_INFINITE_RECURSION = YES;
200208
CLANG_WARN_INT_CONVERSION = YES;
209+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
210+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
201211
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
212+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
213+
CLANG_WARN_STRICT_PROTOTYPES = YES;
202214
CLANG_WARN_SUSPICIOUS_MOVE = YES;
203215
CLANG_WARN_UNREACHABLE_CODE = YES;
204216
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

Heap Sort/Tests/Tests.xcodeproj/xcshareddata/xcschemes/Tests.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0820"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
@@ -46,6 +47,7 @@
4647
buildConfiguration = "Debug"
4748
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4849
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
50+
language = ""
4951
launchStyle = "0"
5052
useCustomWorkingDirectory = "NO"
5153
ignoresPersistentStateOnLaunch = "NO"

0 commit comments

Comments
 (0)