diff --git a/codes/swift/chapter_sorting/bucket_sort.swift b/codes/swift/chapter_sorting/bucket_sort.swift index 5da508414..40266a872 100644 --- a/codes/swift/chapter_sorting/bucket_sort.swift +++ b/codes/swift/chapter_sorting/bucket_sort.swift @@ -12,7 +12,7 @@ func bucketSort(nums: inout [Double]) { // 1. 将数组元素分配到各个桶中 for num in nums { // 输入数据范围 [0, 1),使用 num * k 映射到索引范围 [0, k-1] - let i = Int(num * k) + let i = Int(num * Double(k)) // 将 num 添加进桶 i buckets[i].append(num) } diff --git a/codes/swift/chapter_tree/binary_search_tree.swift b/codes/swift/chapter_tree/binary_search_tree.swift index f0be742ca..21894c4e1 100644 --- a/codes/swift/chapter_tree/binary_search_tree.swift +++ b/codes/swift/chapter_tree/binary_search_tree.swift @@ -123,7 +123,7 @@ class BinarySearchTree { // 当子节点数量 = 0 / 1 时, child = null / 该子节点 let child = cur?.left != nil ? cur?.left : cur?.right // 删除节点 cur - if cur != root { + if cur !== root { if pre?.left === cur { pre?.left = child } else { @@ -131,7 +131,7 @@ class BinarySearchTree { } } else { // 若删除节点为根节点,则重新指定根节点 - root = cur; + root = child } } // 子节点数量 = 2