Skip to content

Commit ea14103

Browse files
authored
Merge pull request kodecocodes#394 from Moon1102/master
update code
2 parents cae6d08 + 12b0bdb commit ea14103

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Linear Search/LinearSearch.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ func linearSearch<T: Equatable>(_ array: [T], _ object: T) -> Int? {
44
}
55
return nil
66
}
7+
8+
func linearSearch1<T: Equatable>(_ array: [T], _ object: T) -> Array<T>.Index? {
9+
return array.index { $0 == object }
10+
}

Radix Sort/RadixSortExample.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Select Minimum Maximum/README.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ array.minElement() // This will return 3
6868
array.maxElement() // This will return 9
6969
```
7070

71+
```
72+
let array = [ 8, 3, 9, 4, 6 ]
73+
//swift3
74+
array.min() // This will return 3
75+
array.max() // This will return 9
76+
```
77+
7178
## Maximum and minimum
7279

7380
To find both the maximum and minimum values contained in array while minimizing the number of comparisons we can compare the items in pairs.

0 commit comments

Comments
 (0)