We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 69cb42e commit 0837113Copy full SHA for 0837113
Radix Sort/RadixSortExample.swift
@@ -0,0 +1,29 @@
1
+//
2
+// RadixSortExample.swift
3
4
5
+// Created by Cheer on 2017/3/2.
6
7
8
+
9
+import Foundation
10
11
+func radixSort1(_ arr: inout [Int]) {
12
13
+ var temp = [[Int]](repeating: [], count: 10)
14
15
+ for num in arr { temp[num % 10].append(num) }
16
17
+ for i in 1...Int(arr.max()!.description.characters.count) {
18
19
+ for index in 0..<temp.count {
20
21
+ for num in temp[index] {
22
+ temp[index].remove(at: temp[index].index(of: num)!)
23
+ temp[(num / Int(pow(10, Double(i)))) % 10].append(num)
24
+ }
25
26
27
28
+ arr = temp[0]
29
+}
0 commit comments