Skip to content

Commit 8e4dbdb

Browse files
committed
Convert to Swift 3 syntax to get rid of Xcode 8 errors
1 parent dca1e2c commit 8e4dbdb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Counting Sort/CountingSort.playground/Contents.swift

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

3-
enum CountingSortError: ErrorType {
3+
enum CountingSortError: Error {
44
case ArrayEmpty
55
}
66

@@ -11,9 +11,9 @@ func countingSort(array: [Int]) throws -> [Int] {
1111

1212
// Step 1
1313
// Create an array to store the count of each element
14-
let maxElement = array.maxElement() ?? 0
14+
let maxElement = array.max() ?? 0
1515

16-
var countArray = [Int](count: Int(maxElement + 1), repeatedValue: 0)
16+
var countArray = [Int](repeating: 0, count: Int(maxElement + 1))
1717
for element in array {
1818
countArray[element] += 1
1919
}
@@ -29,7 +29,7 @@ func countingSort(array: [Int]) throws -> [Int] {
2929

3030
// Step 3
3131
// Place the element in the final array as per the number of elements before it
32-
var sortedArray = [Int](count: array.count, repeatedValue: 0)
32+
var sortedArray = [Int](repeating: 0, count: array.count)
3333
for element in array {
3434
countArray[element] -= 1
3535
sortedArray[countArray[element]] = element
@@ -38,4 +38,4 @@ func countingSort(array: [Int]) throws -> [Int] {
3838
}
3939

4040

41-
try countingSort([10, 9, 8, 7, 1, 2, 7, 3])
41+
try countingSort(array: [10, 9, 8, 7, 1, 2, 7, 3])

0 commit comments

Comments
 (0)