Skip to content

Commit d44abb8

Browse files
committed
Updated radixSort argument to swift3 syntax.
1 parent 10c7a5f commit d44abb8

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Radix Sort/radixSort.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,42 @@
55
*/
66

77

8-
func radixSort(inout arr: [Int] ) {
9-
10-
8+
// NOTE: This implementation does not handle negative numbers
9+
func radixSort(_ array: inout [Int] ) {
1110
let radix = 10 //Here we define our radix to be 10
1211
var done = false
1312
var index: Int
1413
var digit = 1 //Which digit are we on?
15-
16-
14+
15+
1716
while !done { //While our sorting is not completed
1817
done = true //Assume it is done for now
19-
18+
2019
var buckets: [[Int]] = [] //Our sorting subroutine is bucket sort, so let us predefine our buckets
21-
20+
2221
for _ in 1...radix {
2322
buckets.append([])
2423
}
25-
26-
27-
for number in arr {
24+
25+
26+
for number in array {
2827
index = number / digit //Which bucket will we access?
2928
buckets[index % radix].append(number)
3029
if done && index > 0 { //If we arent done, continue to finish, otherwise we are done
3130
done = false
3231
}
3332
}
34-
33+
3534
var i = 0
36-
35+
3736
for j in 0..<radix {
3837
let bucket = buckets[j]
3938
for number in bucket {
40-
arr[i] = number
39+
array[i] = number
4140
i += 1
4241
}
4342
}
44-
43+
4544
digit *= radix //Move to the next digit
4645
}
4746
}

0 commit comments

Comments
 (0)